-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaArraylist.java
More file actions
47 lines (37 loc) · 1.32 KB
/
JavaArraylist.java
File metadata and controls
47 lines (37 loc) · 1.32 KB
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
40
41
42
43
44
45
46
47
import java.util.*;
public class JavaArraylist {
public static void main(String[] args) {
ArrayList<ArrayList<Integer>> arr = new ArrayList<>();
Scanner input = new Scanner(System.in);
int noOfRows = input.nextInt();
System.out.println("Number of Rows: " + noOfRows);
for (int i = 0; i < noOfRows; i++) {
int noOfValues = input.nextInt();
System.out.println("Number of Values: " + noOfValues);
ArrayList<Integer> values = new ArrayList<>();
for (int j = 0; j < noOfValues; j++) {
values.add(input.nextInt());
}
arr.add(values);
}
int noOfQueries = input.nextInt();
System.out.println("Number of Queries: " + noOfQueries);
List<Object> result = new ArrayList<>();
for (int i = 0; i < noOfQueries; i++) {
int row = input.nextInt();
int column = input.nextInt();
try {
result.add(arr.get(row - 1).get(column - 1));
}
catch(Exception e) {
result.add("ERROR!");
}
}
input.close();
System.out.println(arr);
System.out.println("Result: ");
for (Object object : result) {
System.out.println(object);
}
}
}