题解 | #记负均正II#
记负均正II
https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
import java.util.ArrayList; import java.util.List; import java.util.Scanner; import java.util.stream.IntStream; /** * @author hll[yellowdradra@foxmail.com] * @since 2023-04-01 12:26 **/ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); List<Integer> list = new ArrayList<>(); while (in.hasNextInt()) { list.add(in.nextInt()); } System.out.printf("%d\n", list.stream().mapToInt(Integer::valueOf).filter(x -> x < 0).count()); System.out.printf("%.1f\n", list.stream().mapToInt(Integer::valueOf).filter(x -> x >= 0).average().orElse(0)); } }