Find the third max from input four number

import java.io.*;
class Max
{
public static void main(String args[])
{
int a,b,c,d,max1=0,max2=0,max3=0,max4=0;
Console con = System.console();
System.out.print("enter value of a");
a=Integer.parseInt(con.readLine());
System.out.print("enter value of b");
b=Integer.parseInt(con.readLine());
System.out.print("enter value of c");
c=Integer.parseInt(con.readLine());
System.out.print("enter value of d");
d=Integer.parseInt(con.readLine());
if(a>b)
{
max1=a;
max2=b;
}
else
{ max1=b;
max2=a;
}
if(c>max1)
{
max3=max2;
max2=max1;
max1=c;
}
else if(c>max2)
{
max3=max2;
max2=c;
}
else
max3=c;
if(d>max1)
{
max4=max3;
max3=max2;
max2=max1;
max1=d;
}
else if(d>max2)
{
max4=max3;
max3=max2;
max2=d;
}
else if(d>max3)
{
max4=max3;
max3=d;
}
else
max4=d;
System.out.println("max1 ="+max1+"\n max2 ="+max2+"\n max3 ="+max3+"\n max4 ="+max4);
}
}

Comments