题解 | #记负均正#--循环统计,保留一位小数

记负均正

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int posCount = 0;
        int negCount = 0;
        int posSum = 0;
        for (int i = 0; i < num; i++) {
            int n = in.nextInt();
            if (n > 0) {
                posCount++;
                posSum += n;
            } else if (n == 0) {
                continue;
            } else {
                negCount++;
            }
        }
        System.out.print(negCount + " ");
        if (posCount == 0) {
            System.out.println(0.0);
        } else {
            System.out.printf("%.01f", (posSum + 0.0) / posCount);
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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