题解 | #记负均正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); scanner.useDelimiter("\n"); int count = 0; double[] sum = new double[2]; while (scanner.hasNextDouble()) { double i = scanner.nextDouble(); if (i>0) { sum[0] += i; sum[1]++; } else if (i<0){ count++; } } System.out.println(count+"\n"+(sum[1]==0?"0.0":String.format("%.1f", sum[0]/sum[1]))); } }