How do i create an application to display “Hello World” string the number of times user inputs a numeric value? Please help me
Ältere Kommentare anzeigen
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
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:
- Create a new project in Android Studio.
- 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();
}
}
}
- Replace the number 5 in the int num = 5; line with the desired input number.
- 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.
Kategorien
Mehr zu Modeling finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!