记负均正II (java)

记负均正II

http://www.nowcoder.com/questionTerminal/64f6f222499c4c94b338e588592b6a62

import java.util.Scanner;
import java.util.ArrayList;

public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> al = new ArrayList<Integer>();
        while(sc.hasNext()){
           al.add(sc.nextInt());
        }
        int count1 = 0,count2 = 0;
        int sum = 0;
        for(int i = 0; i < al.size(); i++){
            if(al.get(i) < 0){
                count1++;
            }else{
                count2++;
                sum += al.get(i);
            }
        }
        System.out.println(count1);
        System.out.printf("%.1f\n",sum * 1.0 / count2);


        sc.close();
    }

}
全部评论
怎么退出输入?
点赞 回复 分享
发布于 2022-08-11 16:07

相关推荐

mq2:我倒是觉得这种敞亮一点好。能接受就去不能就不去呗。 完了跟现在“正常”公司一样,hr说的天花乱坠,进去一看根本就是996核动力牛马,想走又没应届生身份了。岂不是更糟。
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务