题解 | #记负均正#
记负均正
http://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
这道题目思路很简单,最重要的考察点就是对小数点输出的掌握System.out.printf("%.1f\n",float);
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); int fu = 0; int zu= 0; int sum = 0; for(int i = 0;i<n;i++){ int k = sc.nextInt(); if(k<0)fu++; if(k>0){ sum+=k; zu++; } } System.out.printf("%d %.1f\n",fu,(sum*1.0/zu)); } } }