Search This Blog

If you have any problem or question please write in the comments. We will try to solve and send you the solution. Not just that we will also post your problems solution on our blog.

Saturday, 25 June 2011

Java program using nested if


import java.util.*;
class nestedif
{
public static void main (String arg[])
{
Scanner in = new Scanner (System.in);
int a,b,c,d;
System.out.print ("\n\t Enter first number = ");
a=in.nextInt();


System.out.print ("\n\t Enter second number = ");
b=in.nextInt();

System.out.print ("\n\t Enter third number = ");
c=in.nextInt();

 if (a<b)
{
if (a<c)
System.out.println ("\n\t First number is smallest ");
else
System.out.println ("\n\t First number is not smallest");
}
else if (b<a)
{
if (b<c)
System.out.println ("\n\t Second number is smallest ");
else
System.out.println ("\n\t Second number is not smallest ");
}
else
System.out.println ("\n\t Third number is smallest ");

}
}

Note: 
          In the above program, after entering the values, computer will check that either a is less than b or not. If it is than it will check the other if condition in its block. If it is true then it will show the message 
"First number is smallest" otherwise the statement associated with else will be executed and rest of the code will be bypassed.

No comments:

Post a Comment