Java program to print odd and even number from a Java array.

Java Programming Java8Object Oriented Programming

Following is the required program.

Example

Live Demo

public class Tester {
   public static void main(String args[]) {
      int a[] = { 11, 22, 55, 66, 31, 24 };
      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

Odd Numbers:
11
55
31
Even Numbers:
22
66
24
raja
Published on 23-Apr-2018 00:41:54
Advertisements