Java-If-Else-If Ladder

If-Else-If Ladder

The sequence of nested ifs is the if-else-if ladder. Here is the general form of the if-else-if statement:

The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed. The final else acts as a default condition; that is, if all other conditional tests fail, then the last else statement is performed. If there is no final else and all other conditions are false, then no action will take place.

Program

1

Program Source

class Javaapp {

    public static void main(String[] args) {
        
        int mark = 85;
        if(mark<=40)
        {
            System.out.println("fail");
        }
        else if(mark<=60)
        {
            System.out.println("C Grade");
        }
        else if(mark<=80)
        {
            System.out.println("B Grade");
        }
        else if(mark<=100)
        {
            System.out.println("A Grade");
        }
    }
}

Leave a Comment