1. 程式人生 > >L1-022 奇偶分家

L1-022 奇偶分家

給定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 array[] = new int[n];
int count_ou = 0;
int count_ji = 0;
for(int i = 0; i < n; i++){
array[i] = scanner.nextInt();
}
for(int i = 0; i < n; i++){
if(array[i] % 2 == 0){
count_ou++;
}else if(array[i] % 2 != 0){
count_ji++;
}
}
System.out.println(count_ji + " " + count_ou);
scanner.close();
}
}