题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int count = 0;
int nonCount = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
int t = in.nextInt();
if (t < 0) {
count++;
} else if (t > 0) {
nonCount++;
sum += t;
}
}
System.out.print(count + " ");
if (nonCount == 0) {
System.out.printf("%.1f", 0.0);
} else {
System.out.printf("%.1f", (float)sum / nonCount);
}
}
}
查看8道真题和解析