-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoWhileExam.java
More file actions
38 lines (30 loc) · 982 Bytes
/
Copy pathDoWhileExam.java
File metadata and controls
38 lines (30 loc) · 982 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
34
35
36
37
38
package com.java;
import java.util.Scanner;
public class DoWhileExam {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int choice;
do {
System.out.println("\n--- Menu ---");
System.out.println("1. Say Hello");
System.out.println("2. Say Bye");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("Hello!");
break;
case 2:
System.out.println("Bye!");
break;
case 3:
System.out.println("Exiting program...");
break;
default:
System.out.println("Invalid choice, try again.");
}
} while (choice != 3);
sc.close();
}
}