Java if statement (original) (raw)

Last Updated : 14 Oct, 2025

In Java, an if statement is the simplest decision-making statement. It is used to execute a block of code only if a specific condition is true. If the condition is false, the code inside the if block is skipped.

**Syntax:

if (condition) {
// Statements executed if the condition is true
}

**Example: with Curly Braces

Java `

class GfG{

public static void main(String args[]){
    int i = 10;

    // using if statement
    if (i < 15){
        System.out.println("10 is less than 15");
    }

    System.out.println("Outside if-block");

    // both statements will be printed
}

}

`

Output

10 is less than 15 Outside if-block

**Explanation:

**Example: without Curly Braces

Java `

class GFG { public static void main(String args[]){

    int i = 5;

    // if statement without braces
    if (i > 0)
        System.out.println("i is positive");

    System.out.println(
        "This statement runs regardless of if condition");
}

}

`

Output

i is positive This statement runs regardless of if condition

**Explanation:

Working of if statement

**Flowchart if statement: