-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathShuffle.java
More file actions
25 lines (20 loc) · 758 Bytes
/
Shuffle.java
File metadata and controls
25 lines (20 loc) · 758 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
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
public class Shuffle {
public static void main(String[] args) {
LinkedList<String> list = new LinkedList<>();
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of elements in the list:");
int numberOfElements = scanner.nextInt();
scanner.nextLine();
System.out.println("Enter the elements :");
for (int i = 0; i < numberOfElements; i++) {
String element = scanner.nextLine();
list.add(element);
}
System.out.println("Original list: " + list);
Collections.shuffle(list);
System.out.println("Shuffled list: " + list);
}
}