Write a Program to read integer array from user and separate them in Odd Even list.

 

AIM: Write  a Program to read integer array from user and separate them in Odd Even list.

 

CODE:

import java.util.Scanner;

public class p8

{

   public static void main( String args[] )

    {

Scanner readme = new Scanner(System.in);

             int n; 

             System.out.println("Enter No Elemenys for array\n");

            n=readme.nextInt();

            int a[]=new int[n];

            int odd[]=new int[n];

            int even[]=new int[n];

            System.out.println("Enter"+n+" Elements for array\n");

            for(int i=0;i<n;i++)

            {

                        a[i] = readme.nextInt();

                       if(a[i]%2==0)

                       {

                                   even[i]=a[i];

                       }

                        else

                       {

                                   odd[i]=a[i];

                       }

            }

 

      System.out.println("\nEven");

            for(int i=0;i<n;i++)

            {

                         if(even[i]==0)

                        {

                                   continue;

                        }

                        else

                        {

                                    System.out.println(even[i]);

                        }

       

            }

      System.out.println("\nOdd");

            for(int i=0;i<n;i++)

            {

                        if(odd[i]==0)

                        {

                                   continue;

                        }

                        else

                        {

                                    System.out.println(odd[i]);

                        }

            }

 

   }

}

OUTPUT:



Comments

Popular posts from this blog

Write a program in Java to perform I/O operations on a Text file.

Describe abstract class called Shape which has three subclasses say Triangle, Rectangle, and Circle. Define one method area()in the abstract class and override this area() in these three subclasses to calculate for specific object.

Write a program in Java to demonstrate use of final class.