In this BlueJ program, user will enter three numbers and the program will display the numbers in descending order using nested ifs.
Related Post: BlueJ Programs on Number
import java.util.*;
class Search
{
int
a,b,c;
Scanner sc=new Scanner(System.in);
public void assign()
{
System.out.print("\nEnter 1st
Number:");
a=sc.nextInt();
System.out.print("\nEnter 2nd
Number:");
b=sc.nextInt();
System.out.print("\nEnter 3rd
Number:");
c=sc.nextInt();
}
public void display()
{
if(a>b && a>c)
{
System.out.println("\nHighest = "+a);
if(c>b)
{
System.out.println("\nSecond Highest = "+c);
System.out.println("\nLowest = "+b);
}
else // else of if(c>b)
{
System.out.println("\nSecond Highest = "+b);
System.out.println("\nLowest = "+c);
}
}
else // else of if(a>b && a>c)
{
if(b>a && b>c)
{
System.out.println("\nHighest = "+b);
if(c>a)
{
System.out.println("\nSecond Highest = "+c);
System.out.println("\nLowest =
"+a);
}
else // else of if(b>a && b>c)
{
System.out.println("\nSecond Highest = "+a);
System.out.println("\nLowest = "+c);
}
}
else // else of if(b>a && b>c)
{
System.out.println("\nHighest = "+c);
if(b>a)
{
System.out.println("\nSecond Highest = "+b);
System.out.println("\nLowest = "+a);
}
else
{
System.out.println("\nSecond Highest = "+a);
System.out.println("\nLowest = "+b);
}
} // end of
else of if(b>a && b>c)
} // end of if(b>a && b>c)
}
public static void main(String args[])
{
Search ob=new Search();
ob.assign();
ob.display();
}
}
No comments:
Post a Comment