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 {
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.