7-6 奇偶分家(10 分)

7-6 奇偶分家(10 分)
给定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 sc = new Scanner(System.in);
        int a=sc.nextInt(),b=0,c=0;
        int array[] =new int[a];
        for(int i=0;i<a;i++){
            array[i]=sc.nextInt();
        }
        for(int i=0;i<a;i++){
            if(array[i]%2!=0){
                b=b+1;
            }else{
                c=c+1;
            }
        }
        System.out.println(b+" "+c);
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_38505045/article/details/80163529