题解 | #记负均正II#
记负均正II
https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
import java.util.Scanner;
import java.text.DecimalFormat;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int fnum = 0;
double ztotal = 0;
int znum = 0;
double res = 0.0;
while (sc.hasNext()) {
int n = sc.nextInt();
if (n < 0) {
fnum++;
} else {
znum++;
ztotal = ztotal + n;
}
}
System.out.println(fnum);
if (znum == 0) {
System.out.println(0.0);
} else {
res = ztotal / znum;
DecimalFormat df = new DecimalFormat("0.0");
res = Double.valueOf(df.format(res));
System.out.println(res);
}
}
}
查看10道真题和解析
安克创新 Anker公司福利 817人发布