Synatax:
Program to find largest number between 3 numbers using nested if else.
5Nested.java
if( conditon )
{
Statements;
if( condition ){
}
else
{
}
}
else
{
}
{
Statements;
if( condition ){
}
else
{
}
}
else
{
}
Program to find largest number between 3 numbers using nested if else.
5Nested.java
class NestedIf{
public static void main(String s[]){
int a , b , c;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);
c=Integer.parseInt(s[2]);
System.out.println("\n\n A: "+a+" B: "+b+" C: "+c);
if(a>b)
{
if(a>c)
{
System.out.println(" A is greater");
}
else
{
System.out.println(" C is greater");
}
}
else if(b>c){
System.out.println(" B is greater");
}
else
{
if(c > a)
System.out.println(" C is greater");
else
System.out.println(" All are equal ");
}
}
}
public static void main(String s[]){
int a , b , c;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);
c=Integer.parseInt(s[2]);
System.out.println("\n\n A: "+a+" B: "+b+" C: "+c);
if(a>b)
{
if(a>c)
{
System.out.println(" A is greater");
}
else
{
System.out.println(" C is greater");
}
}
else if(b>c){
System.out.println(" B is greater");
}
else
{
if(c > a)
System.out.println(" C is greater");
else
System.out.println(" All are equal ");
}
}
}
Output: