题解 | #记负均正#难就难在保留一位小数
记负均正
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(); int count = 0; int count1 = 0; int sum = 0; while(n>0){ n--; int num = sc.nextInt(); if(num<0) count++; else if(num>0){ sum +=num;count1++;} } double average = 0; average= count1==0? 0: (double)sum/(count1); String s = String.format("%.1f",average); double res=Double.parseDouble(s); System.out.print(count+" "+res); } }