import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args)throws IOException { //题目有缺陷,实际是单行输入,如果按照多行无法通过 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] strings = reader.readLine().split(" "); int countN = 0; int countP = 0; int sumN = 0; for (int i = 0; i < strings.length; i++) { try {//考虑输入有别的字符 int temp = Integer.parseInt(strings[i]); if (temp < 0) { countN++; } if (temp > 0) { sumN += temp; countP++; } } catch (NumberFormatException e) { } } System.out.println(countN); //处理正数总数为零的情况 除数为0 if (countP > 0) { //四舍五入 用double类型四舍五入函数DecimalFormat 之后小数四舍五入值不对 System.out.print(Math.round(sumN * 10.0 / countP) / 10.0); } else { System.out.print("0.0"); } } }