题解 | #记负均正II#

记负均正II

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner fzhinput = new Scanner(System.in);
        int sz,num=0,i=0;
        float sum=0;
        while(fzhinput.hasNextInt()){
            sz=fzhinput.nextInt();
            if(sz>=0){
                sum+=sz;
            }
            else{
                num++;
            }
            i++;
        }
        System.out.println(num);
        if(i==num){
            System.out.println(0.0);
        }
        else{
            float pj = sum/(i-num);
            String result = String.format("%.1f",pj);
            System.out.println(result);
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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