Advertisement
zero50x

Генерация строки из заданных слов

Mar 5th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. public class PhraseOMatic {
  2.  
  3.     public static void main (String[] args) {
  4.         // создаём три массива слов
  5.         String[] wordListOne = {"blue", "white", "brown", "cream"};
  6.         String[] wordListTwo = {"srrong", "danger", "visible", "sunshine"};
  7.         String[] wordListThree = {"toaster", "car", "pump", "door"};
  8.        
  9.         // вычисляем сколько слов в каждом массиве
  10.         int oneLength = wordListOne.length;
  11.         int twoLength = wordListTwo.length;
  12.         int threeLength = wordListThree.length;
  13.        
  14.         // генерируем 3 случайных числа
  15.         int rand1 = (int) (Math.random() * oneLength);
  16.         int rand2 = (int) (Math.random() * twoLength);
  17.         int rand3 = (int) (Math.random() * threeLength);
  18.        
  19.         // строим фразу
  20.         String phrase = wordListOne[rand1] + " " + wordListTwo[rand2]  + " " + wordListThree[rand3] ;
  21.        
  22.         //Выводим на экран
  23.         System.out.println("Вот что нам нужно: " + phrase);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement