题解 | #记负均正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);
int sum = 0;
int negaCnt = 0;
int zeroCnt = 0;
int otherCnt = 0;
while(in.hasNextInt()) {
int temp = in.nextInt();
if(temp == 0) {
zeroCnt++;
} else if(temp < 0) {
negaCnt++;
} else {
otherCnt++;
sum+=temp;
}
}
System.out.println(negaCnt);
if(sum == 0) {
System.out.println("0.0");
} else {
String avg = String.format("%.1f", (sum/(double)otherCnt));
System.out.print(avg);
}
}
}
网易游戏公司福利 654人发布
