Syntax:
Program to find greatest among 3 numbers using if else if ladder.
6IFelseIFladder.java
if( condition)
{
statements;
}
else if( condition )
{
statements;
}
else if( condition )
{
statements;
}
else
{
statements;
}
{
statements;
}
else if( condition )
{
statements;
}
else if( condition )
{
statements;
}
else
{
statements;
}
Program to find greatest among 3 numbers using if else if ladder.
6IFelseIFladder.java
/*
IF else If ladder
*/
class If_else_If_ladder{
public static void main(String args[]){
int a=10 , b=20 , c=30;
System.out.println("a= "+a+" b= "+b+" c= "+c);
if(a>b && a>c){
System.out.println("\n A is greater");
}
else if(b>a && b>c){
System.out.println("\n B is greater");
}
else if(c>a && c>b){
System.out.println("\n C is greater");
}
else{
System.out.println("\n All are equals");
}
}
}
IF else If ladder
*/
class If_else_If_ladder{
public static void main(String args[]){
int a=10 , b=20 , c=30;
System.out.println("a= "+a+" b= "+b+" c= "+c);
if(a>b && a>c){
System.out.println("\n A is greater");
}
else if(b>a && b>c){
System.out.println("\n B is greater");
}
else if(c>a && c>b){
System.out.println("\n C is greater");
}
else{
System.out.println("\n All are equals");
}
}
}
Output: