Repository navigation
Expand file tree
/
Copy pathPS26.java
More file actions
51 lines (51 loc) · 1.35 KB
/
Copy pathPS26.java
File metadata and controls
51 lines (51 loc) · 1.35 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
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
ArrayList<String> items = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Options:");
System.out.println("1. Add item");
System.out.println("2. Search item");
System.out.println("3. Remove item");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
System.out.print("Enter item to add: ");
String newItem = scanner.nextLine();
items.add(newItem);
System.out.println("Item added: " + newItem);
break;
case 2:
System.out.print("Enter item to search: ");
String searchItem = scanner.nextLine();
if (items.contains(searchItem)) {
System.out.println(searchItem + " found in the list.");
} else {
System.out.println(searchItem + " not found in the list.");
}
break;
case 3:
System.out.print("Enter item to remove: ");
String removeItem = scanner.nextLine();
if (items.contains(removeItem)) {
items.remove(removeItem);
System.out.println(removeItem + " removed from the list.");
} else {
System.out.println(removeItem + " not found in the list.");
}
break;
case 4:
System.out.println("Exiting...");
scanner.close();
return;
default:
System.out.println("Invalid choice. Please choose again.");
}
}
}
}