题解 | #字符统计#

记负均正

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

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

/**
 * 【记负均正】
 *
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        ArrayList<Integer> arrayList = new ArrayList<>();
        int count = 0;

        int size = sc.nextInt();
        for (int i = 0; i < size; i++) {
            int nextInt = sc.nextInt();
            if (nextInt > 0) {
                arrayList.add(nextInt);
            } else if (nextInt < 0){
                count++;
            }
        }

        System.out.print(count + " ");

        if (arrayList.size() == 0) {
            System.out.println(0.0);
        } else {
            count = 0;
            for (Integer integer : arrayList) {
                count = count + integer;
            }
            System.out.printf("%.1f%n", (float) count / arrayList.size());
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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