题解 | #记负均正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 in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
int i = 0;
int j = 0;
int sum = 0;
while (in.hasNextInt()) { // 注意 while 处理多个 case
int curr = in.nextInt();
if(curr<0){
i++;
}else{
j++;
sum = sum + curr;
}
}
System.out.println(i);
//题比较简单,主要是保留1位小数, “%.1d\n”和“1.0*sum”
if(j==0){
System.out.printf("%.1f\n",0.0);
}else{
System.out.printf("%.1f\n",1.0*sum/j);
}
}
}