forked from ddthien-coder/trainingjava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Switchcase.java
31 lines (30 loc) · 915 Bytes
/
Switchcase.java
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
public class Switchcase {
public static void main(String[] args) {
int a =2;
// int, short,byte,char,enum,string
if(a==1) {
System.out.println("Gia tri a la 1");
}else if(a==2) {
System.out.println("Gia tri a la 2");
}else if (a==3) {
System.out.println("Gia tri a la 3");
} else {
System.out.println("Khong phai gia tri 1,2,3");
}
// thay the bang switch
switch (a) {
case 1:
System.out.println("Gia tri a la 1");
break;
case 2:
System.out.println("Gia tri a la 2");
break;
case 3:
System.out.println("Gia tri a la 3");
break;
default:
System.out.println("Khong phai gia tri 1,2,3");
break;
}
}
}