Day 1: if else

In Java, if-else is a control flow statement used to execute certain blocks of code based on whether a condition is true or false. Syntax: if (condition) { // Code to execute if condition is true } else { // Code to execute if condition is false } Example: int number = 10; if (number > 0) { System.out.println("The number is positive."); } else { System.out.println("The number is not positive."); } How it works: The condition inside the if statement is evaluated. If it's true, the code block inside the if is executed. If it's false, the code block inside the else is executed. Let me know if you want to go over else-if or nested if too!

Apr 11, 2025 - 19:51
 0
Day 1: if else

In Java, if-else is a control flow statement used to execute certain blocks of code based on whether a condition is true or false.

Syntax:

if (condition) {
    // Code to execute if condition is true
} else {
    // Code to execute if condition is false
}

Example:

int number = 10;

if (number > 0) {
    System.out.println("The number is positive.");
} else {
    System.out.println("The number is not positive.");
}

How it works:

  • The condition inside the if statement is evaluated.
  • If it's true, the code block inside the if is executed.
  • If it's false, the code block inside the else is executed.

Let me know if you want to go over else-if or nested if too!