题解 | #记负均正II#
记负均正II
http://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int zs = 0; int fs = 0; double zsSum = 0.0; while (in.hasNextDouble()) { double d = in.nextDouble(); if (d > 0.0){ zs++; zsSum += d; } else { fs++; } } System.out.println(fs); if (zs > 0){ double avg = zsSum / zs; System.out.println( String.format("%.1f",avg) ); } else { System.out.println("0.0"); } } }