java - 运行时错误正在抛出,我不知道为什么
问题描述
这个问题在HackerRank上的问题解决类别中被命名为稀疏数组,我遇到了运行时错误。我刚开始使用 Java,在谷歌上搜索了很多之后,我无法调试它。
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);
}
}
解决方案
推荐阅读
- python - 余弦相似度的幼稚实现有什么问题?
- android - 即使在设置 match_parent 之后也留下空白
- hyperhtml - hyperHTML for 10,000 Buttons
- azure-web-app-service - 重新启动 Azure 应用服务修复异常
- prestashop - Prestashop 信用卡支付模块
- php - 使用 JsonModel 返回一个空数组作为对象
- python - Iterparse big XML,内存占用少,并获取所有,甚至嵌套的序列元素
- swift3 - 如何在pdfkit swift中添加圆形注释?
- pytorch - 如何在 Google Colab 上安装 PyTorch v1.0.0+?
- mongodb - Mongodb聚合,对象内的对象总和