number of integers

Given k (1 < k < 100) positive integers, each of which is greater than or equal to 1 and less than or equal to 10. Write a program to count the number of occurrences of 1, 5, and 10 given k positive integers.
Input The
input has two lines: the first line contains a positive integer k, and the second line contains k positive integers, each of which is separated by a space.
Output The
output has three lines, the first line is the number of occurrences of 1, the second line is the number of occurrences of 5, and the third line is the number of occurrences of 10.
Sample input
5
1 5 8 10 5

Sample output
1
2
1

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n,m,i,number1=0,number5=0,number10=0;
        n=scan.nextInt();
        int[] a=new int[n];
        for(i=0;i<n;i++){
            a[i]=scan.nextInt();
            if(a[i]==1)
                number1++;
            if(a[i]==5)
                number5++;
            if(a[i]==10)
                number10++;
        }
        System.out.println(number1);
        System.out.println(number5);
        System.out.println(number10);
    }

}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326617896&siteId=291194637