Answer the question
In order to leave comments, you need to log in
How to implement random text output in Java?
There is a code that displays random text from an array:
String[] texts = {"Привет", "Пока", "Уже виделись"};
Random random = new Random ();
int pos = random.nextInt(texts.length);
System.out.print(texts[pos]);
Answer the question
In order to leave comments, you need to log in
Well anyway
String[] texts = {"Привет", "Пока", "Уже виделись"};
Random random = new Random();
for (int i = 0; i < 10000; i++) {
int pos = random.nextInt(texts.length);
if (i % 10 == 0) {
System.out.print(texts[pos] + "\n");
} else {
System.out.print(texts[pos] + " ");
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question