题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
import java.util.Scanner;
import java.text.DecimalFormat;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int countL0 = 0;
int countG0 = 0;
int sum = 0;
for(int i=0; i<n; i++){
int num = sc.nextInt();
if(num < 0) countL0++;
if(num > 0){
sum += num;
countG0++;
}
}
String avg = "0.0"; // .format()返回string
if(countG0 != 0){
DecimalFormat df = new DecimalFormat("0.0");
avg = df.format((float)sum/(float)countG0); //java除法保留小数:int强转为float
}
System.out.println(countL0 + " " + avg);
}
}