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 demonstrate single inheritance, multilevel inheritance and hierarchical inheritance.

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

Write a java program to create 3 threads using Thread class. Three threads should calculate the sum of 1 to 5, 6 to 10 and 11to 15 respectively. After all thread finishes main thread should print the sum and average.