Loading

16 、(5分)求课程成绩的总分和平均分

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

题目描述
    一个学生考了数学、英语、语文三门,求总分和平均分。
输入
    输入三个整数,中间空格隔开,分别表示数学、英语、语文三门成绩。
输出
    输出两行,第一行输出总分,第二行输出平均分,其中平均分保留两位小数。请注意行尾输出换行。
样例输入
90 85 90
样例输出
265
88.33

思路:简单运算,注意一下格式就好了

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(a + b + c);
        System.out.printf("%.2f\n", (a + b + c) / 3.0);
    }
}

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