Loading

19 、(5分)成绩的学分绩点计算

Java语言程序设计实训题目练习

题目描述
    某校学生评比采用绩点制,规则是:90分以上(含90分,下同)算5点,80分以上算4点,70分以上算3点,60分以上算2点,不及格算0点,请根据某个学生的成绩及学分计算该生该门课程所获得的绩点。
输入
    标准输入,输入的第一行为需要计算用例个数N,接下来的N行,每行有两个浮点数,第一个数为某课程的考试成绩,第二个数为该课程的学分值。
输出
    标准输出,每一行输出一个学生的某课程计算得到的绩点数(结果保留一位小数),请注意行尾输出换行。
样例输入
3
85 1.5
90 3
50 4
样例输出
6.0
15.0
0.0

思路:记得保留一位小数

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while ( n-- > 0 ) {
            double score = sc.nextDouble();
            double weight = sc.nextDouble();
            double point = 0.0;
            if ( score >= 90.0 ) point = 5.0;
            else if ( score >= 80.0 ) point = 4.0;
            else if ( score >= 70.0 ) point = 3.0;
            else if ( score >= 60.0 ) point = 2.0;
            System.out.printf("%.1f\n", weight * point);
        }
    }
}

posted @ 2022-05-16 20:23  qing影  阅读(14)  评论(0)    收藏  举报  来源