In this
program user will enter three numbers (all are unique values)and the output
will be like:
The
smallest number:
The
second higher number:
The
highest number:
BlueJ Program
import
java.io.*;
class Num
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
int a,b,c;
public void show()throws Exception
{
System.out.print("\nEnter first
number:");
a=Integer.parseInt(br.readLine());
System.out.print("\nEnter second
number:");
b=Integer.parseInt(br.readLine());
System.out.print("\nEnter third
number:");
c=Integer.parseInt(br.readLine());
if(a< b && a< c)
{
System.out.println("\nThe
smallest number:"+a);
if(b< c)
{
System.out.println("The
second higher number:"+b);
System.out.println("The
highest number:"+c);
}
else
{
System.out.println("The
second higher number:"+c);
System.out.println("The
highest number:"+b);
}
}
else if(b< a && b<
c)
{
System.out.println("\nThe
smallest number:"+b);
if(a< c)
{
System.out.println("The
second higher number:"+a);
System.out.println("The
highest number:"+c);
}
else
{
System.out.println("The second higher number:"+c);
System.out.println("The
highest number:"+a);
}
}
else if(c< b && c< a)
{
System.out.println("\nThe
smallest number:"+c);
if(a< b)
{
System.out.println("The
second higher number:"+a);
System.out.println("The
highest number:"+b);
}
else
{
System.out.println("The second higher number:"+b);
System.out.println("The
highest number:"+a);
}
}
}
public static void main(String
args[])throws Exception
{
Num ob=new Num();
ob.show();
}
}
Sample Input and Output
Enter first number:22
Enter second
number:44
Enter
third number:12
The
smallest number:12
The
second higher number:22
The
highest number:44
No comments:
Post a Comment