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 (;
int a,b,c,d;
System.out.print ("\n\t Enter first number = ");

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

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

 if (a<b)
if (a<c)
System.out.println ("\n\t First number is smallest ");
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 ");
System.out.println ("\n\t Second number is not smallest ");
System.out.println ("\n\t Third number is smallest ");


          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