-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExerciseSix.java
More file actions
68 lines (51 loc) · 1.87 KB
/
Copy pathExerciseSix.java
File metadata and controls
68 lines (51 loc) · 1.87 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package UnitFour;
import java.util.ArrayList;
import java.util.Scanner;
public class ExerciseSix {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
ArrayList<Integer> num = new ArrayList<>();
num.add(5);
num.add(4);
num.add(3);
num.add(2);
num.add(1);
boolean running = true;
while (running){
System.out.println("Menu:");
System.out.println("1. Add number");
System.out.println("2. Show number");
System.out.println("3. Check number");
System.out.println("4. Exit");
System.out.println("Enter your choose from 1 to 4: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice){
case 1:
System.out.println("Enter number: ");
int newNumbers = scanner.nextInt();
scanner.nextLine();
num.add(newNumbers);
System.out.println("The numbers is added");
break;
case 2:
System.out.println("All numbers is "+num);
break;
case 3:
System.out.println("Enter number: ");
int checkedNumbers = scanner.nextInt();
scanner.nextLine();
if(num.contains(checkedNumbers)){
System.out.println(checkedNumbers+" is on the list");
}else {
System.out.println(checkedNumbers+" is not on the list");
}
break;
case 4:
running = false;
System.out.println("Goodbye");
break;
}
}
}
}