- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx5Condition.java
More file actions
Latest commit
75 lines (69 loc) · 2.23 KB
/
Copy pathEx5Condition.java
File metadata and controls
75 lines (69 loc) · 2.23 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
69
70
71
72
73
74
75
packageJavaEntry;
publicclassEx5Condition {
publicstaticvoidmain(String[] arg){
// Check Simple condition
shortx = 10;
shorty = 20;
if(x > y){
System.out.println("X is greater than Y");
}else {
System.out.println("Y is greater than X");
}
// Check Multiple condition
shortcurrentTime = 14;
if(currentTime < 10){
System.out.println("Good Morning");
}elseif(currentTime > 10 && currentTime < 16){
System.out.println("Good Afternnon");
}elseif(currentTime > 20){
System.out.println("Good Night");
}
// Shorthand condition
shortage = 20;
StringisAdult = age >= 18 ? "Adult" : "Not Adult";
System.out.println(isAdult);
// Instead of writing many if..else statements, we can use the switch statement.
shortcurrentMonth = 5;
switch (currentMonth) {
case1:
System.out.println("Month is January");
break;
case2:
System.out.println("Month is February");
break;
case3:
System.out.println("Month is March");
break;
case4:
System.out.println("Month is April");
break;
case5:
System.out.println("Month is May");
break;
case6:
System.out.println("Month is June");
break;
case7:
System.out.println("Month is July");
break;
case8:
System.out.println("Month is August");
break;
case9:
System.out.println("Month is September");
break;
case10:
System.out.println("Month is October");
break;
case11:
System.out.println("Month is November");
break;
case12:
System.out.println("Month is December");
break;
default:
System.out.println("Number is not a valid month");
break;
}
}
}