题解 | 记负均正II

import java.text.DecimalFormat;
import java.util.Scanner;

public class HJ105 {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
        int b=0;
        int d=0;
        int c=0;
        int e=0;
       while (sc.hasNextInt()) {
           int a = sc.nextInt();
           if (a<0) {
               b++;
           }else if (a==0) {
               d++;
           }else{
               c+=a;
               e++;
           }
       }
        System.out.println(b);
       if (e==0){
           System.out.println(0.0);
       }else {
           double db = c/e;
           DecimalFormat df = new DecimalFormat("0.0");
           String formattedNum= df.format(db);
           System.out.println(formattedNum);//输出是39461.0
           System.out.printf("%.1f\n",db);//输出是39461.0
       }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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