首先输入要输入的整数个数n,然后输入n个整数。输出为n个整数中负数的个数,和所有正整数的平均值,结果保留一位小数。
首先输入一个正整数n,
然后输入n个整数。
输出负数的个数,和所有正整数的平均值。
5 1 2 3 4 5
0 3
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNext()) { int n = in.nextInt(); double sum = 0; int nums = 0; int count = 0; for(int i = 0; i < n; i++) { int input = in.nextInt(); if(input < 0) { nums ++; } else if(input > 0){ count ++; sum += input; } } double ave = Math.round(sum/count*10)/10.0; System.out.print(nums + " " + ave); } } }
原文:http://www.cnblogs.com/zywu/p/5815716.html