Lanqiao Cup Practice---Score Statistics

Blue Bridge Cup Java Group Practice—Score Statistics

topic description

Xiaolan organized an exam for the students. The total score of the paper is 100 points, and each student's score is an integer from 0 to 100.
A score of at least 60 is called a pass. A score of at least 85 is considered excellent.
Please calculate the pass rate and excellent rate, expressed as a percentage, and the part before the percentage sign is rounded to an integer.

enter description

The first line of input contains an integer n (1≤n≤10 4), indicating the number of people taking the test.
Next n lines, each line contains an integer from 0 to 100, representing a student's score.

output description

Output two lines, each with a percentage, indicating the passing rate and the excellent rate respectively. The part before the percent sign is rounded to an integer.
insert image description here
code:

import java.util.Scanner;

public class Main{
    
    
    public static void main(String [] args){
    
    
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int jige = 0, youxiu = 0;
        int con = 0; // 记录
        while(con < n) {
    
    
            int grade = sc.nextInt();
            if(grade >= 60 && grade <= 100) {
    
    
                jige++;
            }
            if(grade >= 85 && grade <= 100) {
    
    
                youxiu++;
            }
            con++;
        }
        double print1 = (jige * 1.0) / n; // 及格率
        double print2 = (youxiu * 1.0) / n; // 优秀率
        System.out.println((Math.round(print1 * 100)) + "%");
        System.out.println((Math.round(print2 * 100)) + "%");
    }
}

Math.round(value): 将value四舍五入为最接近的整数,也可以理解为返回最接近value的整数,如果有两个,则选择最大的那一个。

Guess you like

Origin blog.csdn.net/weixin_45832482/article/details/122482722