题解 | #记负均正II#

记负均正II

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

思路:多定义几个变量记录即可。

public class Main{
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        double num1 = 0;
        int count1 = 0;
        int count2 = 0;
        while(sc.hasNextInt()){
            int temp  = sc.nextInt();
            if(temp>=0){
                num1+=temp;
                count1++;
            }
            else {
                count2++;
            }
        }
        System.out.println(count2);
        System.out.println(count1==0?0.0:String.format("%.1f", num1/count1));
    }
}
全部评论

相关推荐

头像
08-28 09:05
门头沟学院
投递美团等公司10个岗位
点赞 评论 收藏
分享
Hyh_111:像这种hr就不用管了,基本没啥实力,换一个吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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