记负均正

题目描述

首先输入要输入的整数个数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);
        }
    }

}
             
            

 

posted @ 2016-08-28 19:24  no_one  阅读(464)  评论(0编辑  收藏  举报