Program to find second highest among four numbers.

import java.io.*;
class hello
{    public static void main(String[] asd)throws IOException
{
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
int n1,n2,n3,n4,max;
String num;
System.out.println("Enter the all four numbers::");
num=obj.readLine();
n1=Integer.parseInt(num);
num=obj.readLine();
n2=Integer.parseInt(num);
num=obj.readLine();
n3=Integer.parseInt(num);
num=obj.readLine();
n4=Integer.parseInt(num);
if(n1>n2 && n1>n3 && n1>n4) n1=0;
else if(n2>n1 && n2>n3 && n2>n4) n2=0;
else if(n3>n2 && n3>n1 && n3>n4) n3=0;
else if(n4>n2 && n4>n3 && n4>n1) n4=0;
else System.out.println("ALL ARE EQUAL.");
if(n1>n2 && n1>n3 && n1>n4) System.out.println("Second highest is "+n1+".");
else if(n2>n1 && n2>n3 && n2>n4) System.out.println("Second highest is "+n2+".");
else if(n3>n2 && n3>n1 && n3>n4) System.out.println("Second highest is "+n3+".");
else if(n4>n2 && n4>n3 && n4>n1) System.out.println("Second highest is "+n4+".");
else System.out.println("We have more then one second highest.");

}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s