Skip to main content

Java if-else ladder with a example program.

Introduction:-

  Today we shall check about the if-else ladder it is simlar to the if-else statement only the difference is that we can combine a if statement with the else we should have a example program with the syntax and whole bunch of stuff . We also provide a download link in bellow . You are free to change the code and if you wish to share the modified code share with us in the comments.


What is the Syntax of the if -else ladder or if -else if ?

  Syntax:-
   if(Condition){
    Statement 1
    Statement 2
    Statement 3
  ..............   
}
else if(condition){
  Statement 1
  Statement 2
  Statement 3
  .................
}
else{
   Statement 1
   Statement 2
   Statement 3
  ................
}
  

How to write the java program code for the ladder ?

Code Statement :- Program to find greatest of the three number using if -else ladder.

Code:-
 class condition1{
  public static void main(String[] args){
int a = 5;
int b = 6;
int c = 7;
if(a>b && a>c){
System.out.println("The Greatest number is "+a);
}
else if(b>c){
System.out.println("The Greatest number is "+b);
}
else{
System.out.println("The Greatest number is "+c);
}
}
}

OUTPUT:-
  The Greatest number is 7

Here is the download link of the Source code.

  So , if your found this post usefull try to share it with your friends who are learing java . As "knowledge increases by Sharing " . Do check other post posted on this blog about the java programing and setup on the local setup. 

Comments