题解 | #记负均正II#
记负均正II
http://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
用默认的double类型做除法比较好一点。 增加 if(li>=1e6) continue;判断
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner in = new Scanner(System.in); int minusCount=0; int postCount=0; double sumPostive=0; while(in.hasNextInt()){ int li = in.nextInt(); if(li>=1e6) continue; if(li<0){ ++ minusCount; }else { ++ postCount; sumPostive +=li; } } System.out.println(minusCount); System.out.printf("%.1f\n", sumPostive/postCount); } }