-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConditionals.java
56 lines (50 loc) · 1.48 KB
/
Conditionals.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
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
public class Conditionals{
public static void main(String args[]){
// IF ELSE CONDITIONS
int x = 18;
if (x>18 && x<=20){
System.out.println("Hello");
}else{
System.out.println("Bye");
}
// if-else-else_if
if(x>18){
System.out.println("You are an adult." + x);
}else if(x>60){
System.out.println("You are Being Old " + x);
}
// we can add as many as else_if statements in between for mutliple conditions
else{
System.out.println("Get Out Of Here");
}
// ternery
x = 5;
int y = 7;
int result = (x>y)?x:y;
System.out.println(result);
// Switch Statement
int n = 7;
switch(n){
case 1:
System.out.println("Monday.");
break;
case 2:
System.out.println("Tuesday.");
break;
case 3:
System.out.println("Wednesday.");
break;
case 4:
System.out.println("Thursday.");
break;
case 5:
System.out.println("Friday.");
break;
case 6:
System.out.println("Saturday.");
break;
default:
System.out.println("Sunday");
}
}
}