Как зациклить определенную строчку кода в Java
Во время изучения java по книге написал код и хотел бы зациклить лишь строчку, которая выводит текст пользователю на экран
class PhraseGeneration{
public static void main(String[] args) {
String[] wordListOne = {"small", "big", "enormous", "giant"};
String[] wordListTwo = {"green", "red", "blue", "pink"};
String[] wordListThree = {"umbrella", "doll", "coat", "building"};
int oneLength = wordListOne.length;
int twoLength = wordListTwo.length;
int threeLength = wordListThree.length;
int rand1 = (int)(Math.random() * oneLength);
int rand2 = (int)(Math.random() * twoLength);
int rand3 = (int)(Math.random() * threeLength);
String pharse = wordListOne [rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3];
while (true)
System.out.print("I'm really dissapointed by that code " + pharse);
}
}
ниже пример, как я пытался вывести именно эту строку в цикл, так же я пробовал перенести out.print в отдельные фигурные скобки, но в этом случае программа не могла найти int pharse
Элемент списка
Ответы (1 шт):
Автор решения: Roman Konoval
→ Ссылка
Судя по всему вы хотите в цикле генерировать фразы:
while (true) {
int rand1 = (int)(Math.random() * oneLength);
int rand2 = (int)(Math.random() * twoLength);
int rand3 = (int)(Math.random() * threeLength);
String pharse = wordListOne [rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3];
System.out.print("I'm really dissapointed by that code " + pharse);
}