1. 题目
读题
考查点
2. 解法
思路
代码逻辑
具体实现
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.valueOf(sc.nextLine());
String[] nums = sc.nextLine().split("\\s+");
count(nums);
}
public static void count(String[] nums) {
int negCnt = 0;
int posCnt = 0;
double posSum = 0;
for (int i = 0; i < nums.length; i++) {
int num = Integer.valueOf(nums[i]);
if (num < 0) {
negCnt++;
} else if (num > 0) {
posCnt++;
posSum += num;
}
}
String avg;
if (posCnt == 0) {
avg = "0.0";
} else {
avg = new DecimalFormat("#0.0").format((double) posSum / posCnt);
}
System.out.print(negCnt + " " + avg);
}
}