Advertisement
Dido09

WordRandomizer

Feb 23rd, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class ObejctsAndClasses {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. String[] words = scanner.nextLine().split(" ");
  9.  
  10. Random rnd = new Random();
  11.  
  12. for (int i = 0; i < words.length; i++) {
  13. int swapIndex = rnd.nextInt(words.length);
  14.  
  15. String tmp = words[i];
  16. words[i] = words[swapIndex];
  17. words[swapIndex] = tmp;
  18. }
  19. for (int i = 0; i < words.length; i++) {
  20. System.out.println(words[i]);
  21. }
  22.  
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement