- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackerrankJava0030.java
More file actions
Latest commit
39 lines (31 loc) · 960 Bytes
/
Copy pathHackerrankJava0030.java
File metadata and controls
39 lines (31 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
importjava.util.ArrayList;
importjava.util.List;
importjava.util.Scanner;
publicclassHackerrankJava0030 {
publicstaticvoidmain(String[] args) {
// Java Arraylist
// https://www.hackerrank.com/challenges/java-arraylist/problem?isFullScreen=true
Scannerscanner = newScanner(System.in);
List<List<Integer>> intList = newArrayList<>();
intnumberOfList = scanner.nextInt();
for (inti = 0; i < numberOfList; i++) {
inttmpListSize = scanner.nextInt();
List<Integer> tmpList = newArrayList<>();
for (intj = 0; j < tmpListSize; j++) {
tmpList.add(scanner.nextInt());
}
intList.add(tmpList);
}
intnumberOfQuery = scanner.nextInt();
for (inti = 0; i < numberOfQuery; i++) {
intx = scanner.nextInt() - 1;
inty = scanner.nextInt() - 1;
try {
System.out.println(intList.get(x).get(y));
} catch (IndexOutOfBoundsExceptione) {
System.out.println("ERROR!");
}
}
scanner.close();
}
}