题解 | #记负均正#
记负均正
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); } }