Java statistical results with the number of students

Description Title:
input of the first line of N data denotes
a second input line of N data values specific
third input line of a value of
the output of the third row of the same number of elements

Knowledge Point: add the data into the list, and then traverse the list, with the given values ​​are the same count ++,

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StatisticalScore {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        while(in.hasNextInt()){
            int N=in.nextInt();//N个数据
            if(N==0){
                break;
            }
            List<Integer> list=new ArrayList<>();//存放输入的整型分数
            for(int i=0;i<N;i++){
                //输入N个数据
                list.add(in.nextInt());
            }
            int  score=in.nextInt();
            //遍历list找到与score相同的数的个数
            int count=0;//存储符合要求的个数
            for(int a:list){//遍历list,每一项为a
             if(score==a){
             count++;
             }

            }
            System.out.println(count);//打印在循坏里面
                }
    }
}

Guess you like

Origin blog.51cto.com/14232658/2453458
Recommended