Planforexams.com

How to print ODD and EVEN elements from an array in java

can i buy prednisone over the counter in usa The blog provides the technical approach on ” how to find the ODD and EVEN array elements in a one dimensional array” 

click this link here now Problem Statement:

Identify ODD and EVEN elements in one dimensional array 

Solution Approach:

package com.java.planforexams.array;
import java.util.Scanner;
public class OddEvenArrayElements {
	public static void main(String[] args) {
		// Scanner object for reading User Input
		Scanner scan = new Scanner(System.in);
		int count;
		// Receive the Array Element Count from User
		System.out.print("Provide the Array Element Count : ");
		// Get the Array Count
		count = scan.nextInt();
		//Set the Array Size with Count value
		int arrayInputFromUser[] = new int[count];
		// Receive the Array Elements from User.
		System.out.println("Enter the elements:");
     	// Iterate the array elements
		for (int incr=0; incr<count; incr++)
		{
			arrayInputFromUser[incr] = scan.nextInt();
		}
    	for(int incr = 0 ; incr < count ; incr++)
        {
            if(arrayInputFromUser[incr] % 2 == 0)
            {
                System.out.print(" \n Array Element is EVEN::: "+ 
                                 arrayInputFromUser[incr]);
            }
            else {
                System.out.print(" \n Array Element is ODD::: "+ 
                                 arrayInputFromUser[incr]);
            }
        }
	}
}
Output:
Provide the Array Element Count : 4
Enter the elements:
12
11
34
33
 
 Array Element is EVEN::: 12 
 Array Element is ODD::: 11 
 Array Element is EVEN::: 34 
 Array Element is ODD::: 33
Exit mobile version