Friday, 30 March 2018

Find odd or even Numbers in an Array

package com.tutorial4u;

import java.util.Scanner;

/*Java Program to Find odd or even Numbers in an Array*/
public class EvenOrOddInArray {
     public static void main(String[] args) {
           Scanner sc = new Scanner(System.in);

           System.out.print("Enter the size of Array : ");
           int num = sc.nextInt();
           int arr[] = new int[num];
           System.out.println("Enter all the element : ");
           for(int i=0;i<num;i++){
                arr[i]=sc.nextInt();
           }
           for (int i = 0; i <num; i++) {
                if (arr[i] % 2 == 0)
                      System.out.println("even");
                else
                      System.out.println("odd");
           }
     }
}


Output:

Enter the size of Array : 5
Enter all the element :
22
21
33
42
24
even
odd
odd
even
even

No comments:

Post a Comment

No of Occurrence in Array

package com.tutorial4u; import java.util.HashMap; /************************************************************  No of Occurrence in Array...