if…..else Statement

 

if…..else Statement

In an if…..else statement we have two blocks of code, wherein the former block of code (code inside if statement) is executed if condition evaluates to true and the later block of code (code inside else statement) is executed if the condition is false.


Syntax:

if (condition) {
	//block of code
} else {
	//block of code
}

maxoncodes

Example:

public class JavaIf {
    public static void main(String[] args) {
        String name = "Maxon";
        int Roll = 25;
        if (name == "Maxon" && Roll == 26) {
            System.out.println("Details of Maxon.");
        } else {
            System.out.println("Invalid details.");
        }
    }
}

 

Output:

Invalid details.