题解 | 求平均数

求平均数

https://www.nowcoder.com/practice/41e59cee1221424bb9291435aae79ae9

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        //write your code here......
        

        //输出格式为:System.out.println(String.format("%.2f",avg));
        int count = 0;
        int sum = 0;
        int temp = 0;
        while((temp = scan.nextInt()) >= 0){
            sum += temp;
            count++;
        }

        double avg = (sum * 1.0) / (count * 1.0);

        System.out.println(String.format("%.2f",avg));
    }
}

全部评论

相关推荐

06-12 16:00
天津大学 Java
牛客30236098...:腾讯坏事做尽,终面挂是最破防的 上次被挂了后我连简历都不刷了
点赞 评论 收藏
分享
07-02 22:46
门头沟学院 Java
码农索隆:hr:“管你投没投,先挂了再说”
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务