We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
ArrayList<ArrayList<Integer>> lines = new ArrayList<>();
for (int i = 0; i < n; i++) {
int d = scanner.nextInt();
ArrayList<Integer> line = new ArrayList<>();
for (int j = 0; j < d; j++) {
line.add(scanner.nextInt());
}
lines.add(line);
}
int q = scanner.nextInt();
for (int i = 0; i < q; i++) {
int x = scanner.nextInt();
int y = scanner.nextInt();
try {
int number = lines.get(x - 1).get(y - 1);
System.out.println(number);
} catch (IndexOutOfBoundsException e) {
System.out.println("ERROR!");
}
}
scanner.close();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Arraylist
You are viewing a single comment's thread. Return to all comments →
import java.util.ArrayList; import java.util.Scanner;
public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt();
}