给定N个正整数,请统计奇数和偶数各有多少个?
输入第一行给出一个正整N(≤1000);第2行给出N个非负整数,以空格分隔。
在一行中先后输出奇数的个数、偶数的个数。中间以1个空格分隔。
9
88 74 101 26 15 0 34 22 77
3 6
暂无!!
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] numList = new int[N];
for (int i = 0; i < N; i++) {
numList[i] = scanner.nextInt();
}
int countOdd = 0;
int countEven = 0;
for (int i = 0; i < numList.length; i++) {
if(numList[i] % 2 == 0){
countEven++;
}else{
countOdd++;
}
}
System.out.print(countOdd + " " + countEven);
}
}