Java Program to Print Odd and Even Numbers from an array

In this tutorial you will learn about the Java Program to Print Odd and Even Numbers from an array and its application with practical example.

In this tutorial, we will learn to create a Java Program to Print Odd and Even Numbers from an array using java programming.

Prerequisites

Before starting with this tutorial, we assume that you are best aware of the following Java programming concepts:

  • Java Operators.
  • Basic Input and Output function in Java.
  • Class and Object in Java.
  • Basic Java programming.
  • If-else statements in Java.
  • For loop in Java.

What is Even and Odd Number.

A number which is  divisible by 2 is called even number (number%2==0) after dividing 2 remainder remain zero.
A number which is not divisible by 2 is called an odd number (number%2 !=0) after dividing 2 remainder remains.

Java Program to Print Odd and Even Numbers from an array

In this program we will find number in an array are even  or odd using if else statement and loop. We would first declared and initialized the required variables. Next,  we will find that number is even or odd.lets have a look at the code.

Output

Even and odd in an array.

In the above program, we have first declared and initialized a set variables required in the program.

  • arr= it will hold array values
  • i=  for iteration .

After declaring variables we initiate values in a an array[].

Algorithm

  1. Declare an array and an element in array[].
  2. within the loop find element even or odd applying condition separate for even a shown in image below.

  1. Print the even elements by checking the conditions using for loop.

  1. within the loop find element even or odd applying condition separate for odd a shown in image below.

this is the source code of the Java Program to Print the Odd & Even Numbers in an Array.

In this tutorial we have learn about the Java Program to Print Odd and Even Numbers from an array and its application with practical example. I hope you will like this tutorial.