I have the code given to me by my classm8 which tells the largest , 2nd largest , 3rd largest and smallest number.
but I can't understand how his code works.Can someone explain this to me?
import javax.swing.JOptionPane;
import javax.swing.JDialog;
public class exer1
{
public static void main(String args[])
{
JDialog.setDefaultLookAndFeelDecorated(true);
int a = 0, b=1000000, c=-1000000, temp = 0,d=0,temp2 = 0;
String s1 = " ";
for(int i=1;i<=10;i++)
{
int n1=Integer.parseInt(JOptionPane.showInputDialog("Enter a number"));
s1 = s1 + " " + n1;
if(i==1)
a = n1;
else
{
temp2 = d;
if(n1>c)
{
d = c;
c = n1;
if(c>a)
{
temp = a;
a = c;
c = temp;
}
}
if(n1>d && n1<c)
d = n1;
}
if(n1<b)
b = n1;
}
JOptionPane.showMessageDialog(null,"Numbers are" + (s1) + "\nHighest number inputted is " + (a)
+ "\nSecond highest number inputted is " + (c)
+ "\nThird highest number inputted is " + (d)
+ "\nLowest number inputted is " + (b));
}
}