-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditionals.java
More file actions
71 lines (68 loc) · 1012 Bytes
/
conditionals.java
File metadata and controls
71 lines (68 loc) · 1012 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
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
//if Statement
int age=20;
if(age>=18)
{
System.out.println("eligible");
}
//if-else Statement
int number=5;
if(number%2==0)
{
System.out.println("even");
}
else
{
System.out.println("odd");
}
//if-else if-else Ladder
int marks=85;
if(marks>=90)
{
System.out.println("Grade A");
}
else if(marks>=75)
{
System.out.println("Grade B");
}
else if(marks>=60)
{
System.out.println("Grade C");
}
else
{
System.out.println("Fail");
}
//Nested if Statement
int age=25;
boolean hasID=true;
if(age>=18)
{
if(hasID)
{
System.out.println("entry allowed");
}
else
{
System.out.println("iD required");
}
}
else
{
System.out.println("not eligible");
}
//switch Statement
int day=3;
switch(day)
{
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
default:
System.out.println("Invalid day");
}