Advertisement
2018powjocr

Untitled

Feb 22nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /**
  2. * tester will create a 10 item array with random elements, and then it will shuffle them.
  3. *
  4. * @Jocelyn
  5. * @2/22/17
  6. */
  7. public class tester
  8. {
  9. public static void main(String[] args)
  10. {
  11. int[] arr = new int[10];
  12. System.out.println("Array without shuffling");
  13. for(int i = 0; i < arr.length; i++)
  14. {
  15. arr[i] = (int)(Math.random() * 10 + 1);
  16. System.out.print(arr[i] + " ");
  17. }
  18.  
  19. System.out.println();
  20.  
  21. System.out.println("Array with shuffling");
  22. for(int j = 0; j < arr.length; j++)
  23. {
  24. int x = (int)(Math.random() * 10);
  25. int temp = arr[j];
  26. arr[j] = arr[x];
  27. arr[x] = temp;
  28. }
  29. for(int k = 0; k < arr.length; k++)
  30. {
  31. System.out.print(arr[k] + " ");
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement