Even & Odd numbers

 avatar
unknown
plain_text
2 years ago
1.9 kB
4
Indexable
package javaapplication21;

import javax.swing.JOptionPane;

/**
 *
 * @author attasam
 */
public class JavaApplication21 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int num1,num2;  

  

                String oddNums="" ,evenNums="";  

  

        do{  

  

             num1=Integer.parseInt(JOptionPane.showInputDialog(null," Enter the First Number"));  

  

             if(num1 <=0){  

  

                  JOptionPane.showMessageDialog(null,"It must be above  0" );  

  

             }  

  

        }while(num1 <=0);  

  

         

  

        do{  

  

              num2=Integer.parseInt(JOptionPane.showInputDialog(null," Enter the Second Number"));  

  

              if(num2<num1 && num2>0)  

  

              {  

  

                  JOptionPane.showMessageDialog(null,"The number "+num2+ "  must be bigger than first number "+num1 );  

  

              }  

  

              else if(  num2<= 0){  

  

                   JOptionPane.showMessageDialog(null,"It must be above  0" );  

  

              }  

  

        }while( num2 <num1);  

  

            

        for(int x=num1; x<=num2; x++ ){  

  

              

  

            if(x%2!=0){  

  

                oddNums+= x+" ";  

  

            }  
            else{
                evenNums+=x+" ";
            }

  

        }  

  

        JOptionPane.showMessageDialog(null,"the Odd numbers between "+num1 + " and "+num2 +" is : " + oddNums+"\n"+
               "the Even numbers between "+num1 + " and "+num2 +" is : " + evenNums );  

  

       // int n=JOptionPane.showConfirmDialog(null, "Do you want to continue with the program ","Title",JOptionPane.YES_NO_OPTION);  

  
    }
    
}
Editor is loading...