题解 | #记负均正#

记负均正

https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int n = in.nextInt();
            int[] nums = new int[n];
            int count = 0; //负数个数
            int count2 = 0; //0的个数
            double sum = 0.0;  //正数和

            for(int i = 0; i< n; i++){
                nums[i] = in.nextInt();
                if(nums[i] < 0) count++;
                else if(nums[i] == 0) count2++;
                else sum += nums[i];
            }
            System.out.print(count + " ");
            if(sum == 0.0) System.out.print(0.0);
            else System.out.printf("%.1f" , sum/(n - count - count2));
            
        }
    }
}

全部评论

相关推荐

头像
01-29 18:11
海南大学 Java
奔跑的suechil...:单从项目看这个简历不怕被问穿吗 带微服务的项目需要相当多的项目理解和经验诶
点赞 评论 收藏
分享
01-14 16:23
广州商学院 Java
双非后端失败第N人:如果准备好了可以直接投字节,字节是最不看学历的,只要想面,大概率都能给你约面。
双非有机会进大厂吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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