【发布时间】:2019-01-25 05:21:23
【问题描述】:
https://www.hackerrank.com/challenges/java-arraylist/probleminput
5
5 41 77 74 22 44
1 12
4 37 34 36 52
0
3 20 22 33
5
1 3
3 4
3 1
4 3
5 5
样本输出
74
52
37
错误!
错误!
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList array[] = new ArrayList[n];
for(int i = 0; i < n; ++i)
{
ArrayList list = new ArrayList();
int no = sc.nextInt();
while(no != '\n')
{
list.add(no);
no = sc.nextInt();
}
array[i] = list;
}
int k = sc.nextInt();
int l = sc.nextInt();
System.out.println(array[k].get(l));
}
}
错误(标准错误) 线程“主”java.util.NoSuchElementException 中的异常
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Solution.main(Solution.java:18)
【问题讨论】:
-
你想通过这个程序达到什么目的?
-
@NicholasK ive 给出了上一节中的演示 ..
-
@LanaLightman 上面给出的链接不再起作用,你能用hackerrank的原始问题更新问题吗