필터 지우기
필터 지우기

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