import java.util.Arrays; import java.util.Random; public class Demo { public static void main(String[] args) { int[] arr = { 20, 40, 60, 80,100, 120, 140, 160, 180, 200}; System.out.println("The integer array = "+Arrays.toString(arr)); Random rand = new Random(); for(int i = 0; i<arr.length; ++i) { int index = rand.nextInt(arr.length - i); int tmp = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = arr[index]; arr[index] = tmp; } System.out.println("Shuffle integer array = "+Arrays.toString(arr)); } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more