题解 | #记负均正#
记负均正
http://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
import java.util.*;
public class Main{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
int Nnum = 0; //负数
int Pnum = 0; //正数
int sum = 0; //正数之和
for (int i = 0; i < n; i++) {
int m = sc.nextInt();
if(m < 0){
Nnum++;
}else if(m > 0){
sum += m;
Pnum++;
}
}
double avg = 0.0; //平均数
if(Pnum != 0){
avg = (double)sum / (double)Pnum;
}else {
avg = 0;
}
/*
%. 表示 小数点前任意位数
1 表示保留1位小数
f 表示浮点型
*/
System.out.println(Nnum + " " + String.format("%.1f",avg));
}
}