Thursday, 1 September 2016

Java Program (Find Out Greater and Smaller Age)

FIND OUT SMALLER AND LARGER AGE FROM TAKEN INPUT (SWING PACKAGE)


import javax.swing.JOptionPane;
    class FiveAge{
        public static void main(String[]args) throws Exception{
            String text = JOptionPane.showInputDialog("Enter First Age");
            int Age1 = Integer.parseInt(text);

            String text2 = JOptionPane.showInputDialog("Enter Second Age");
            int Age2 = Integer.parseInt(text2);

            String text3 = JOptionPane.showInputDialog("Enter Third Age");
            int Age3 = Integer.parseInt(text3);
   
            String text4 = JOptionPane.showInputDialog("Enter Fourth Age");
            int Age4 = Integer.parseInt(text4);
   
            String text5 = JOptionPane.showInputDialog("Enter Fifth Age");
            int Age5 = Integer.parseInt(text5);
   
            if( Age1 > Age2 && Age1 > Age3 && Age1 > Age4 && Age1 > Age5 )
            JOptionPane.showMessageDialog( null, Age1 + " is Greater" );
       
            if( Age2 > Age1 && Age2 > Age3 && Age2 > Age4 && Age2 > Age5 )
            JOptionPane.showMessageDialog( null, Age2 + " is Greater" );
       
            if( Age3 > Age1 && Age3 > Age2 && Age3 > Age4 && Age3 > Age5 )
            JOptionPane.showMessageDialog(null, Age3 + " is Greater" );
       
            if ( Age4 > Age1 && Age4 > Age2 && Age4 > Age3 && Age4 > Age5 )
            JOptionPane.showMessageDialog( null, Age4 + " is Greater" );
       
            if( Age5 > Age1 && Age5 > Age2 && Age5 > Age3 && Age5 > Age4 )
            JOptionPane.showMessageDialog( null, Age5 + " is Greater" );
   
            if( Age1 < Age2 && Age1 < Age3 && Age1 < Age4 && Age1 < Age5 )
            JOptionPane.showMessageDialog(null, Age1 + " is Smaller" );
       
            if( Age2 < Age1 && Age2 < Age3 && Age2 < Age4 && Age2 < Age5 )
            JOptionPane.showMessageDialog(null, Age2 + " is Smaller" );
       
            if( Age3 < Age1 && Age3 < Age2 && Age3 < Age4 && Age3 < Age5 )
            JOptionPane.showMessageDialog( null, Age3 + " is Smaller" );
       
            if( Age4 < Age1 && Age4 < Age2 && Age4 < Age3 && Age4 < Age5 )
            JOptionPane.showMessageDialog( null, Age4 + " is Smaller" );
       
            if( Age5 < Age1 && Age5 < Age2 && Age5 < Age3 && Age5 < Age4 )
            JOptionPane.showMessageDialog(null, Age5 + " is Smaller" );      
        }
    }

No comments:

Post a Comment