How to find out Even or Odd number from a list of an Array ?

How to find out Even or Odd number from a list of an Array ?

Previous Home Next

 

This java program is used to find out the even or odd number from the list of an array. 


 number[i] %2==0
  this method is used to find out the even or odd number from the list .
if the remender became zero the number is even otherwise it is odd

int [] number is a array of 10 elements
for loop is used to get  the length of the array till last number.
(number.length ) is used to get the length of an array.

number[i] %2==0 check the value of array
 if remender will 0 the number will be print as even
otherwise odd.

 
public class EvenOdd {
public static void main(String[] args) {
//create an array of 10 numbers
int[] numbers = new int[]{2,9,6,4,3,8,25,10,11,32};

for(int i=0; i < numbers.length; i++){

if(numbers[i]%2 == 0)
System.out.println(numbers[i] + " The is even number.");
else
System.out.println(numbers[i] + " The is odd number.");
}


}

}

2  The number is even
9 The number is odd
6 The number is even
4 The number is even
3 The number is odd
8 The number is even
25 The number is odd
10 The number is even
11 The number is odd
32 The number is even
Previous Home Next