题解 | #记负均正#
记负均正
http://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
保留一位小数
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
int n = scan.nextInt();
int[] nums = new int[n];
int sum = 0;
double sum1 = 0;
int index = 0;
for(int i = 0; i<n; i++){
nums[i] = scan.nextInt();
}
for(int i : nums){
if(i<0){
sum++;
}
else if(i>0){
sum1 += i;
index++;
}
}
System.out.print(sum + " ");
if(index == 0){
System.out.print("0.0");
}
else{
System.out.print(String.format("%.1f",sum1/index));
}
}
scan.close();
}
}