Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Java else-if Statements

    Java Programming Tutorials


    else if statements in Java is like another if condition, it's used in the program when if statement having multiple decisions.

    The basic format of else if statement is:

    Syntax:

    if(test_expression)
    {
       //execute your code
    }
    else if(test_expression n)
    {
       //execute your code
    }
    else
    {
       //execute your code
    }

    Example of a Java Program to Demonstrate else If statements

    Example:

    public class Sample {
    
        public static void main(String args[]) {
            int a = 30, b = 30;
    
            if (b > a) {
                System.out.println("b is greater");
            }
            else if(a > b){
                System.out.println("a is greater");
            }       
            else {
                System.out.println("Both are equal");
            }
        }
    }

    Program Output:

    java-else-if-statements



    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.