-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitch Statement | ChineseZodiac
More file actions
39 lines (39 loc) · 1.66 KB
/
Copy pathSwitch Statement | ChineseZodiac
File metadata and controls
39 lines (39 loc) · 1.66 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
import java.util.Scanner;
public class Practice{
public static void main(String[] args) {
//ChineseZodiac
Scanner input = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = input.nextInt();
//Switch Statement
switch (year % 12){
case 0 : System.out.println("Monkey");break;
case 1 : System.out.println("Rooster");break;
case 2 : System.out.println("Dog");break;
case 3 : System.out.println("Pig");break;
case 4 : System.out.println("Rat");break;
case 5 : System.out.println("Ox");break;
case 6 : System.out.println("Tiger");break;
case 7 : System.out.println("Rabit");break;
case 8 : System.out.println("Dragon");break;
case 9 : System.out.println("Snake");break;
case 10 : System.out.println("Horse");break;
case 11 : System.out.println("Sheep");break;
}
//Enhanced Switch Statement
// switch (year % 12) {
// case 0 -> System.out.println("Monkey");
// case 1 -> System.out.println("Rooster");
// case 2 -> System.out.println("Dog");
// case 3 -> System.out.println("Pig");
// case 4 -> System.out.println("Rat");
// case 5 -> System.out.println("Ox");
// case 6 -> System.out.println("Tiger");
// case 7 -> System.out.println("Rabit");
// case 8 -> System.out.println("Dragon");
// case 9 -> System.out.println("Snake");
// case 10 -> System.out.println("Horse");
// case 11 -> System.out.println("Sheep");
// }
}
}