if else if ladder in java

Опубликовано: 29 Сентябрь 2024
на канале: Tarun Sir
94
8

In this video you will learn that what is if else if ladder statement in java.
In if else ladder we use several if else one after another. Its syntax looks like a ladder.
If(condition1)
{ _______________;
}
else
if(condition2)
{_______________;
}
else
if(condition3)
{_______________;
}
else
{_______________;
}


In Ladder if condition1 is true then its related statements are executed, condition2 and condition3 will not be evaluated. Condition2 is checked only when condition1 is false, similarly condition3 is checked only when condition1 and condition2 both are false. In short a condition is checked only when its previous condition is false. The last else part is executed only when all the conditions are false. Last else is not compulsory it is used when required.




import java.util.Scanner;
class MaxAmongThreeLadder
{ public static void main(String[]args)
{ Scanner kb=new Scanner(System.in);
int a,b,c;
System.out.print("Enter value of a : ");
a=kb.nextInt();
System.out.print("Enter value of b : ");
b=kb.nextInt();
System.out.print("Enter value of c : ");
c=kb.nextInt();
if(a>b&&a>c)
{ System.out.println(a+" is the maximum");
}
else
if(b>c)
{ System.out.println(b+" is the maximum ");
}
else
{ System.out.println(c+" is the maximum");
}
}
}
www.tarunsir.com
www.cinstitute.org.in
Connect me on linkedin   / tarrunverrma  
  / the_ultimate_coding_stuff  


#tarunsir #javatutorial #learnprogramming