题解 | #记负均正II#
记负均正II
https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double sum = 0.0; int count = 0; int count2 = 0; while (scanner.hasNext()) { int a = scanner.nextInt(); if (a < 0) { count++; } else { count2++; sum += a; } } System.out.println(count); if (count2>0){ System.out.printf("%.1f", sum / count2); }else { System.out.printf("%.1f", sum); } } }