-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShuffle.java
More file actions
33 lines (29 loc) · 836 Bytes
/
Copy pathShuffle.java
File metadata and controls
33 lines (29 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
class Shuffle {
// shuflle logic
public static void shuffle(int arr[]) {
int temp, r, i;
for (i = arr.length - 1; i >= 0; i--) {
r = (int) (Math.random() * (i + 1));
temp = arr[r];
arr[r] = arr[i];
arr[i] = temp;
System.out.print(arr[i] + " ");
}
}
// main method
public static void main(String[] args) {
int size, i;
Scanner s = new Scanner(System.in);
System.out.print("The size of the array:");
size = s.nextInt();
// array implementation
int arr[] = new int[size];
for (i = 0; i < size; i++) {
arr[i] = s.nextInt();
}
System.out.print("\nThe Shuffled elements are:");
// method call
shuffle(arr);
}
}