Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PhraseOMatic {
- public static void main (String[] args) {
- // создаём три массива слов
- String[] wordListOne = {"blue", "white", "brown", "cream"};
- String[] wordListTwo = {"srrong", "danger", "visible", "sunshine"};
- String[] wordListThree = {"toaster", "car", "pump", "door"};
- // вычисляем сколько слов в каждом массиве
- int oneLength = wordListOne.length;
- int twoLength = wordListTwo.length;
- int threeLength = wordListThree.length;
- // генерируем 3 случайных числа
- int rand1 = (int) (Math.random() * oneLength);
- int rand2 = (int) (Math.random() * twoLength);
- int rand3 = (int) (Math.random() * threeLength);
- // строим фразу
- String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3] ;
- //Выводим на экран
- System.out.println("Вот что нам нужно: " + phrase);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement