题解 | #记负均正#

记负均正

http://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8

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

相关推荐

阿武同学:基本信息保留前面三行,其他的可以全部删掉,邮箱最重要的你没写,主修课程精简到8个以内,实习里面2/3/4都是水内容的,非要写的话建议两到三句话,项目经历排版优化下,自我评价缩到三行
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

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