Advertisement
Lyubohd

01. Randomize Words

Jun 23rd, 2021
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import java.util.Random;
  4. import java.util.Scanner;
  5. import java.util.stream.Collectors;
  6.  
  7. public class Main {
  8.     public static void main(String[] args) {
  9.         Scanner scan = new Scanner(System.in);
  10.         List<String> words = Arrays.stream(scan.nextLine().split(" ")).collect(Collectors.toList());
  11.         Random rnd = new Random();
  12.         while (words.size() > 0) {
  13.             String word = words.remove(rnd.nextInt(words.size()));
  14.             System.out.println(word);
  15.         }
  16.     }
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement