题解 | #求平均数#

求平均数

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

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = 0;
        double avg = 0;
        //write your code here......
        int count = 0;
        while((a = sc.nextInt()) > 0){
            avg = avg + a;
            count++;
        }
        avg = avg / count;
        System.out.println(String.format("%.2f",avg));
        //输出格式为:System.out.println(String.format("%.2f",avg));
        

    }
}

全部评论

相关推荐

递归到脑子变傻:杭州还有上位机用VB的,实在没绷住
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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