题解 | #记负均正II#

记负均正II

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

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int negativeNums = 0;
        int nonnegativeNums = 0;
        double nonnegativeTotal = 0.0;
        while (scan.hasNext()) {
            int val = Integer.valueOf(scan.nextLine().trim());
            if (val < 0) {
                negativeNums++;
            } else {
                nonnegativeNums++;
                nonnegativeTotal += val;
            }
        }
        System.out.println(negativeNums);
        if (nonnegativeNums == 0) {
            System.out.printf("%.1f", 0.0);
        } else {
            System.out.printf("%.1f", nonnegativeTotal / nonnegativeNums);
        }
    }
}
全部评论
该牛油正在参与牛客写题解薅羊毛的活动,牛币,周边,京东卡超多奖品放送,活动进入倒计时!快来捡漏啦https://www.nowcoder.com/discuss/888949?source_id=profile_create_nctrack&channel=-1
点赞 回复 分享
发布于 2022-04-27 11:43

相关推荐

评论
点赞
4
分享
牛客网
牛客企业服务