Java程序打印奇数和偶数


Java程序打印奇数和偶数

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]);

         }

      }

   }

}