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

1 Ansicht (letzte 30 Tage)
For example i need application what can take input of interger number and print out hello world that many time in Android studio

Antworten (1)

Jack
Jack am 3 Apr. 2023
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.

Community Treasure Hunt

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

Start Hunting!

Translated by