Skip to content
Home » Blog » Java if..else Statement

Java if..else Statement

In this tutorial, you’ll learn about Java if..else Statement and how to use it in Java Programs.

Java if..else statement can also be called as control flow statements along with if, if else ladder and switch statement these are used to control the flow of program based on given conditions, so let’s understand Java if..else statement.

if..else Statement

if..else statements are the secondary path of execution when the condition in the if clause evaluated to be false.

Or you can say that if the condition in the if the clause is evaluated to be false then the statements in the else block are executed.

The else block comes immediately after the end of if block.


//Code to executed if condition is true
//Code to executed if condition is false

If the condition is evaluated to be false then control of program would directly jump to end of if statement. The flowchart for if statement can be shown as:

Java if..else Statement Flowchart
Java if..else Statement Flowchart

for the better understanding of Java if..else Statement below are some examples to illustrate the use of if..else Statement in Java.

Program to check whether the number is even or odd using Java if..else Statement

public class IFElseDemo{

     public static void main(String []args){
        int number=11;
            System.out.println("Number is even");
            System.out.println("Number is odd");    


Number is odd

Ask your questions about Java control flow if statement and clarify your/others doubts by commenting. Documentation.

Please write to us at [email protected] to report any issue with the above content or for feedback.

This tutorial is contributed by Ashutosh Sahu