Jul 25, 2024
break
, continue
).if-else
for handling multiple conditions based on a variable.if (condition) {
// statements to execute if condition is true
}
if (condition) {
// if true
} else {
// if false
}
int personAge = 25;
if (personAge >= 18) {
System.out.println("Eligible for voting");
}
if (number % 2 == 0) {
System.out.println("Even number");
} else {
System.out.println("Odd number");
}
if (number > 0) {
System.out.println("Positive");
} else if (number < 0) {
System.out.println("Negative");
} else {
System.out.println("Zero");
}
switch (variable) {
case value1:
// statements
break;
case value2:
// statements
break;
default:
// statements
}
if-else
statements.switch (weekNumber) {
case 1:
System.out.println("Sunday");
break;
case 2:
System.out.println("Monday");
break;
// Additional cases...
default:
System.out.println("Invalid week number");
}
if-else
and ternary operator.if-else
conditions.