题解 | #记负均正II#

记负均正II

https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double sum = 0,  othersTotal = 0;
        int counter = 0;
        while (in.hasNextInt()) {
            int number = in.nextInt();
            if (number < 0) counter++;
            else {
                sum += number;
                othersTotal++;
            }
        }
        System.out.println(counter);
        if(othersTotal!=0) System.out.printf("%.1f\n",sum/othersTotal);
        else System.out.println(0.0);
        in.close();
    }
}

全部评论

相关推荐

06-07 00:00
已编辑
腾讯_后端开发
点赞 评论 收藏
分享
07-30 11:52
门头沟学院 Java
美团暑期实习没投递成功,这次正式批的北斗计划总该有我的一部分了吧!
求职的纳鲁多:大佬投我就不投了,毕竟王不见王,避你锋芒
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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