-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvenAndOddElementsInOneDArray.java
More file actions
37 lines (33 loc) · 1.08 KB
/
EvenAndOddElementsInOneDArray.java
File metadata and controls
37 lines (33 loc) · 1.08 KB
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 EvenAndOddElementsInOneDArray {
public static void main(String[] args) {
/*
* You are given T(number of test cases) integer arrays.
* For each array A, you have to find the value of absolute difference between the counts of even and odd elements in the array.
* */
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
for(int i=0; i<T; i++){
int N = scanner.nextInt();
int[] A = new int[N];
for(int j=0; j<A.length; j++){
A[j] = scanner.nextInt();
}
oddEvenCountDiff(A);
}
}
public static void oddEvenCountDiff(int[] arr){
int oddCount = 0;
int evenCount = 0;
for(int i=0; i<arr.length; i++){
if(arr[i] % 2 == 0){
evenCount++;
}else {
oddCount++;
}
}
System.out.println(evenCount);
System.out.println(oddCount);
System.out.println(Math.abs(evenCount- oddCount));
}
}