首页 > 解决方案 > 运行时错误正在抛出,我不知道为什么

问题描述

这个问题在HackerRank上的问题解决类别中被命名为稀疏数组,我遇到了运行时错误。我刚开始使用 Java,在谷歌上搜索了很多之后,我无法调试它。

Imgur 上的错误

public class Solution {
    private final static Scanner sc = new Scanner(System.in);
    
    public static void main(String[] args) {
        List<Integer> integers = new ArrayList<Integer>();
        List<String> strings = new ArrayList<String>();
        List<String> queries = new ArrayList<String>();
        int n = sc.nextInt();
        for( int i = 0; i < n; i++) {
            strings.add(sc.nextLine());
        }
        int q = sc.nextInt();
        for( int j = 0; j < q; j++) {
            queries.add(sc.nextLine());
        }
        
        for( int k = 0; k < q; k++) {
            int count = 0;
            for( int m = 0; m < q; m++) {
                if(queries.get(k) == strings.get(m)) {
                    count++;
                }
            }
            integers.add(count);
        }
        integers.forEach(System.out::println);
    }
}

标签: java

解决方案


推荐阅读