-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek7b.java
More file actions
54 lines (53 loc) · 1.89 KB
/
week7b.java
File metadata and controls
54 lines (53 loc) · 1.89 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import java.util.Collections;
public class week7b {
public static void main(String[] args) {
ArrayList<Integer> a = new ArrayList<>();
Scanner sc = new Scanner(System.in);
Random r = new Random();
for (int j = 0; j <= 10; j++) {
a.add(r.nextInt(10));
}
while (true) {
System.out.println("OPTIONS : 1.ADD 2.GET 3.REMOVE 4.SET 5.CLEAR 6.SIZE 7.PRINT LIST 8.SORT 9.EXIT");
System.out.println("Enter your Choice");
switch (sc.nextInt()) {
case 1 -> {
System.out.println("Enter the element : ");
a.add(sc.nextInt());
}
case 2 -> {
System.out.println("Enter Index : ");
System.out.println(a.get(sc.nextInt()));
}
case 3 -> {
System.out.println("Enter Index : ");
a.remove(sc.nextInt());
}
case 4 -> {
System.out.println("Enter Index : ");
System.out.println("Enter the element : ");
a.set(sc.nextInt(), sc.nextInt());
}
case 5 -> {
a.clear();
System.out.println("List is Cleared!!!");
}
case 6 -> System.out.println("Size of the list is : " + a.size());
case 7 -> {
for (int x : a) {
System.out.print(x + " ");
}
System.out.println();
}
case 8 -> Collections.sort(a);
case 9 -> {
System.out.println("Exited!!!");
System.exit(0);
}
}
}
}
}