1. 题目
读题
考查点
知识点:
2. 解法
思路
代码逻辑
具体实现
public class HJ105 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Integer> list = new ArrayList<>();
while (sc.hasNext()) {
list.add(Integer.valueOf(sc.nextLine()));
}
sc.close();
count((Integer[]) list.toArray(new Integer[0]));
}
public static void count(Integer[] nums) {
int negCnt = 0;
int unNegCnt = 0;
int unNegSum = 0;
for (int num : nums) {
if (num < 0) {
negCnt++;
} else {
unNegCnt++;
unNegSum += num;
}
}
System.out.println(negCnt);
String unNegAvg;
if (unNegCnt == 0) {
unNegAvg = "0.0";
} else {
unNegAvg = new DecimalFormat("#0.0").format((double) unNegSum / unNegCnt);
}
System.out.println(unNegAvg);
}
}