Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * tester will create a 10 item array with random elements, and then it will shuffle them.
- *
- * @Jocelyn
- * @2/22/17
- */
- public class tester
- {
- public static void main(String[] args)
- {
- int[] arr = new int[10];
- System.out.println("Array without shuffling");
- for(int i = 0; i < arr.length; i++)
- {
- arr[i] = (int)(Math.random() * 10 + 1);
- System.out.print(arr[i] + " ");
- }
- System.out.println();
- System.out.println("Array with shuffling");
- for(int j = 0; j < arr.length; j++)
- {
- int x = (int)(Math.random() * 10);
- int temp = arr[j];
- arr[j] = arr[x];
- arr[x] = temp;
- }
- for(int k = 0; k < arr.length; k++)
- {
- System.out.print(arr[k] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement