-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfElseExample.java
More file actions
52 lines (45 loc) · 1.09 KB
/
Copy pathIfElseExample.java
File metadata and controls
52 lines (45 loc) · 1.09 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
/**
* Day 3 - Control Flow: if, if-else, if-else-if
*
* Concept:
* Conditional statements allow the program to make decisions
* based on certain conditions.
*
* This example demonstrates:
* - Simple if statement
* - if-else statement
* - if-else-if ladder
*
* Real-life analogy:
* Decision making like:
* IF it rains → take umbrella
* ELSE → go normally
*/
public class IfElseExample {
/**
* Main method demonstrating conditional statements
*/
public static void main(String[] args) {
int age = 20;
// Simple if
if (age >= 18) {
System.out.println("Eligible to vote");
}
// if-else
int marks = 40;
if (marks >= 50) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}
// if-else-if ladder
int score = 85;
if (score >= 90) {
System.out.println("Grade A");
} else if (score >= 75) {
System.out.println("Grade B");
} else {
System.out.println("Grade C");
}
}
}