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 scan = new Scanner(System.in);
ArrayList<ArrayList<Integer>> ml = new ArrayList<>();
int n = scan.nextInt();
for (int i = 0; i < n; i++) {
int x = scan.nextInt();
ArrayList<Integer> list = new ArrayList<>();
for (int j = 0; j < x; j++) {
int z = scan.nextInt();
list.add(z);
}
ml.add(list);
}
int m = scan.nextInt();
for(int i=0; i<m; i++){
int a= scan.nextInt();
int b= scan.nextInt();
try{
System.out.println(ml.get(a-1).get(b-1));
}
catch(IndexOutOfBoundsException e){
System.out.println("ERROR!");
}
}
scan.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 →
my code:
import java.util.ArrayList; import java.util.Scanner;
public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in);
}