Java Program to Print Odd and Even Numbers from an Array

To print odd and even numbers from an array in Java, we can achieve this by taking the remainder of each element and checking if it is divisible by 2. If the remainder is 0, the number is even; otherwise, it is odd.

public class OddEvenInArrayExample{  
public static void main(String args[]){  
int a[]={1,2,5,6,3,2};  
System.out.println("Odd Numbers:");  
for(int i=0;i<a.length;i++){  
if(a[i]%2!=0){  
System.out.println(a[i]);  
}  
}  
System.out.println("Even Numbers:");  
for(int i=0;i<a.length;i++){  
if(a[i]%2==0){  
System.out.println(a[i]);  
}  
}  
}}

Output:

In conclusion, by using the remainder operator and checking divisibility by 2, we can easily distinguish and print the odd and even numbers from an array in Java. Follow tutorials.freshersnow.com to learn more.