Loading
Data-structure-with-JAva-Tutorial

Even Odd Program Of Array

Q. Find out the the even and odd number from the given array .


Example :-

input :- 
22 ,20,9,7,8
output :-
Even : 22
Even : 20
Odd  : 9
Odd  : 7
Even : 8

Program Solution :-

import java.util.Scanner;
public class Main
{
  public static void main (String[]args)
  {
    System.out.println("Even Odd Array Program");
    
    
    Scanner input = new Scanner (System.in);
    System.out.println("Enter Array Size");
    int size = input.nextInt ();//taking size input
    
    int[] arr = new int[10];
    
    System.out.println("Enter Array Value");//taking Array Value
    for (int i = 0; i < size; i++)
    {
	 arr[i] = input.nextInt ();
    }
    
    EvenOdd (arr, size); //calling the EvenOdd method
    
  }


  public static void EvenOdd (int[]arr, int size)
  {
    for (int j = 0; j < size; j++)
    {
        
	 if (arr[j] % 2 == 0) //logic for finding even odd
	  {
       System.out.println("Even : " + arr[j]);
	  }
	  
	  else
	  {
	     System.out.println("Odd : " + arr[j]); 
	  }
    }
  }
}

OUTPUT

Even Odd Array Program
Enter Array Size
5
Enter Array Value
22
20
9
7
8
Even : 22
Even : 20
Odd  : 9
Odd  : 7
Even : 8