Program to find the larger number among four numbers.

import java.io.*;
class hello
{ public static void main(String[] asd)throws IOException
{
BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
int n1,n2,n3,n4;
String num;
System.out.println("Enter four numbers::");
num=in.readLine();
n1=Integer.parseInt(num);
num=in.readLine();
n2=Integer.parseInt(num);
num=in.readLine();
n3=Integer.parseInt(num);
num=in.readLine();
n4=Integer.parseInt(num);
if(n1<n2 && n1<n3 && n1<n4) System.out.println("num= "+n1+" is smaller among all four.");
else if(n2<n1 && n2<n3 && n2<n4) System.out.println("num= "+n2+" is greater among all four.");
else if(n3<n2 && n3<n1 && n3<n4) System.out.println("num= "+n3+" is greater among all four.");
else if(n4<n2 && n4<n3 && n4<n1) System.out.println("num= "+n4+" is greater among all four.");
else if(n1==n2 && n1==n3 && n1==n4) System.out.println("ALL are same.");

}
}
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