Ticker

6/recent/ticker-posts

Java (Else if statement)

JAVA ELSE IF STATEMENT





INTRODUCTION
The If-else statement can be used to implement only at-most two logical conditions.
So if you want to implement more than two logical conditions then you can use the else-if statement.
Therefore the else-if statement is used to implement two and more than two logical conditions.


ELSE IF SYNTAX IN JAVA
if (logical condition)
{
statements ...
}

else if (logical condition)
{

statements ...

}


else
{

statements ...

}




ELSE IF  PROGRAM IN JAVA
class Grade
{
public static void main(String as[])
{
int Marks=56;

if(Marks>=33 && Marks<=50)
{
System.out.println("C Grade");
}

else if(Marks>50 && Marks<=75)
{
System.out.println("B Grade");
}

else if(Marks>75 && Marks<=100)
{
System.out.println("A Grade");
}

else
System.out.println("Fail");
}
}

- - - PROGRAM OUTPUT - - -
















HOME

Post a Comment

0 Comments