题解 | #求平均数#

求平均数

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......
        int count = 0;
        float avg = 0;
        int temp = scan.nextInt();
        while(temp > 0){
            count ++;
            avg += temp;
            temp = scan.nextInt();
        }
        avg = avg / count;
        System.out.println(String.format("%.2f", avg));
        //输出格式为:System.out.println(String.format("%.2f",avg));
        

    }
}

全部评论

相关推荐

08-25 14:25
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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