Created
October 5, 2017 20:37
-
-
Save viveknarang/0bd9c956ac956bed5dee992ac061b9b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Random; | |
public class Test5 { | |
public static void main(String[] args) { | |
int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9}; | |
Random r = new Random(); | |
int temp = 0, a = 0, b = 0; | |
for(int i = 0; i < numbers.length; i++) { | |
a = r.nextInt(numbers.length); | |
b = r.nextInt(numbers.length); | |
temp = numbers[a]; | |
numbers[a] = numbers[b]; | |
numbers[b] = temp; | |
} | |
System.out.println(Arrays.toString(numbers)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment