4-9 Maximum

posted Feb 28, 2014, 7:55 AM by Dlovan ismail   [ updated Feb 28, 2014, 7:55 AM by Karwan Jacksi ]
/*
Write a program in java to read n numbers from the keyboard then find two numbers you entered biggest?
*/


package maximum;
import javax.swing.JOptionPane;// Needed for JOptionPane

public class Maximum
{
    public static void main(String[] args) 
    {       
            int Count=Integer.parseInt(JOptionPane.showInputDialog("How many numbers will you enter?"));
            int F_Largest=Integer.parseInt(JOptionPane.showInputDialog("Enter The Number1")),S_Largest=F_Largest,Store;

            for (int i =1; i < Count; i++)
            {
                Store=Integer.parseInt(JOptionPane.showInputDialog("Enter The Number"+(i+1)));

                if(Store > F_Largest)
                {
                    S_Largest=F_Largest;
                    F_Largest=Store;
                } 
                else
                    if(S_Largest<Store||F_Largest==S_Largest)
                        S_Largest=Store;
                        
            }

            JOptionPane.showMessageDialog(null,"First Largest number="+F_Largest+"\nSecond Largest number="+S_Largest);
        
    }   
}

ċ
Maximum.java
(1k)
Karwan Jacksi,
Feb 28, 2014, 7:55 AM
Comments