How do i create an application to display “Hello World” string the number of times user inputs a numeric value? Please help me

1 次查看(过去 30 天)
For example i need application what can take input of interger number and print out hello world that many time in Android studio

回答(1 个)

Jack
Jack 2023-4-3
Here's an example code that takes an input of an integer number and prints "Hello World" that many times in Android Studio:
  1. Create a new project in Android Studio.
  2. In the MainActivity.java file, add the following code:
import android.os.Bundle;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int num = 5; // Change this to the desired input number
for (int i = 0; i < num; i++) {
Toast.makeText(getApplicationContext(), "Hello World", Toast.LENGTH_SHORT).show();
}
}
}
  1. Replace the number 5 in the int num = 5; line with the desired input number.
  2. Run the app and you should see "Hello World" displayed in a Toast message that many times, depending on the input number.
Note: This is just a simple example and there are many other ways to achieve this result in Android Studio.

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by