题解 | #记负均正#

记负均正

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

import java.util.Arrays;
import java.util.Scanner;
import java.util.function.Supplier;
import java.util.stream.IntStream;

/**
 * @author hll[yellowdradra@foxmail.com]
 * @since 2023-03-30 23:45
 **/
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        in.nextLine();
        String[] split = in.nextLine().split(" ");
        Supplier<IntStream> supplier = () -> Arrays.stream(split).mapToInt(Integer::valueOf);
        long negativeCount = supplier.get().filter(x -> x < 0).count();
        double positiveAverage = supplier.get().filter(x -> x > 0).average().orElse(0);
        System.out.printf("%d %.1f\n", negativeCount, positiveAverage);
    }
}

全部评论

相关推荐

11-08 17:36
诺瓦科技_HR
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务