If-Else statements are very handy and easy, they are used just like in the English language "if the condition holds do the following else do the following". Simple as that.


public class IfElseInJava {

    public static void main(String[] args) {
        
        //Simple if-else Statements in java
        // WwW.Code-Blocks.OrG
        
        int three = 3;
        int seven = 7;
        
        int bignumber = 999;
        int smallnumber = 1;
        
        if (three > seven) // Condition
        {//If the condition holds, this block will be executed
             System.out.println("Can 3 be greater than 7?"); 
             System.out.println("You can add here some more lines if you wish."); 
        }
        else
        {//If the condition doesnt hold, this block will be executed
            System.out.println("Three is not greater than seven"); 
            System.out.println("You can add here some more lines if you wish."); 
        }
        
        System.out.println("\n\n");  // Lets leave some space between the sentences with new lines.
        
        // On the example below if condition is true;
        
        
        if (bignumber > smallnumber) // Condition
        {//If the condition holds, this block will be executed
             System.out.println("The big number 999 is greater than 1"); 
             System.out.println("This block will be printed because the condition holds."); 
        }
        else
        {//If the condition doesnt hold, this block will be executed
            System.out.println("Since the condition fails this line wont be executed"); 
            System.out.println("You can add here some more lines if you wish."); 
        }    
        
        System.out.println("\n\n");  // Lets leave some space between the sentences with new lines.
        
        // If condition without curly brackets
        
        if (bignumber < smallnumber)
            System.out.println("If Statement without curly bracket"); // Belongs to if statement, since the if condition doesnt hold, the line will not be printed.
            System.out.println("This line does not belong to if statement, only the line right after the if statement WITHOUT curly brackets belongs to if statement."); // Important
            

    }

}

Below is the output of above code:

Three is not greater than seven
You can add here some more lines if you wish.

The big number 999 is greater than 1
This block will be printed because the condition holds.

This line does not belong to if statement, only the line right after the if statement WITHOUT curly brackets belongs to if statement.