0% found this document useful (0 votes)
2 views2 pages

Java If Syntax

The document explains three types of conditional statements in programming: the simple if statement, the if-else statement, and the if-else if-else statement. Each type is illustrated with examples related to age and marks to demonstrate how conditions affect the flow of code execution. These statements allow for decision-making based on whether conditions are true or false.

Uploaded by

alihassan9410r
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Java If Syntax

The document explains three types of conditional statements in programming: the simple if statement, the if-else statement, and the if-else if-else statement. Each type is illustrated with examples related to age and marks to demonstrate how conditions affect the flow of code execution. These statements allow for decision-making based on whether conditions are true or false.

Uploaded by

alihassan9410r
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

✅ 1.

if statement (simple)

👉 Jab sirf condition true ho tab code chale

if(condition) {
// code runs if condition is true
}

📌 Example:

int age = 18;

if(age >= 18) {


[Link]("You can vote");
}

✅ 2. if-else statement

👉 True ho to ek kaam, false ho to doosra

if(condition) {
// runs if true
} else {
// runs if false
}

📌 Example:

int age = 16;

if(age >= 18) {


[Link]("You can vote");
} else {
[Link]("You cannot vote");
}

✅ 3. if-else if-else statement

👉 Multiple conditions check karne ke liye

if(condition1) {
// runs if condition1 is true
} else if(condition2) {
// runs if condition2 is true
} else {
// runs if all conditions are false
}

📌 Example:

int marks = 75;

if(marks >= 80) {


[Link]("A Grade");
} else if(marks >= 60) {
[Link]("B Grade");
} else if(marks >= 40) {
[Link]("C Grade");
} else {
[Link]("Fail");
}

You might also like