题解 | #记负均正II#

记负均正II

https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62

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

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        List<Integer> low = new ArrayList<>();
        List<Integer> up = new ArrayList<>();
        while (sc.hasNextInt()){
            int in = sc.nextInt();
            if (in < 0 ){
                low.add(in);
            }else{
                up.add(in);
            }

        }

        System.out.println(low.size());
        float temp = 0.0f;
        if (up.size()==0){
            System.out.println(0.0f);
        }else {
            for (Integer num :up) {
                temp+=num;
            }
            System.out.println(String.format("%.1f",temp/up.size()));
        }
    }
}

全部评论

相关推荐

牛马人的牛马人生:一开始看成了网吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务