share

Thursday, 7 May 2015

Check Array Element Even or Odd


Check Array Element  Even or Odd In Java

public class PrintEvenOrOdd {
    public static void main(String[] args) {
       int arr[]={10,2,5,21,37,48};
       for (int i = 0; i < arr.length; i++) {
        System.out.println("element ="+arr[i]+" is even="+isEven(arr[i]));
       }
    }
    private static boolean isEven(int n){
        return((n%2)==0);
    }
}


Output:

element =10 is even=true
element =2 is even=true
element =5 is even=false
element =21 is even=false
element =37 is even=false
element =48 is even=true

No comments:

Post a Comment