forked from Nikhil-2002/Programming_Hactoberfest23
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EvenOddinArray.java
37 lines (28 loc) · 895 Bytes
/
EvenOddinArray.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.Scanner;
public class EvenOddCounter {
public static void countEvenOdd(int[] arr) {
int evenCount = 0;
int oddCount = 0;
for (int num : arr) {
if (num % 2 == 0) {
evenCount++;
} else {
oddCount++;
}
}
System.out.println("Even numbers: " + evenCount);
System.out.println("Odd numbers: " + oddCount);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the size of the array: ");
int size = scanner.nextInt();
int[] array = new int[size];
System.out.println("Enter elements of the array:");
for (int i = 0; i < size; i++) {
array[i] = scanner.nextInt();
}
scanner.close();
countEvenOdd(array);
}
}