题解 | #记负均正II#
记负均正II
http://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int negativeNums = 0;
int nonnegativeNums = 0;
double nonnegativeTotal = 0.0;
while (scan.hasNext()) {
int val = Integer.valueOf(scan.nextLine().trim());
if (val < 0) {
negativeNums++;
} else {
nonnegativeNums++;
nonnegativeTotal += val;
}
}
System.out.println(negativeNums);
if (nonnegativeNums == 0) {
System.out.printf("%.1f", 0.0);
} else {
System.out.printf("%.1f", nonnegativeTotal / nonnegativeNums);
}
}
}