- Prepare
- Java
- Data Structures
- Java Arraylist
- Discussions
Java Arraylist
Java Arraylist
+ 0 comments Scanner in =new Scanner(System.in); int n=in.nextInt(); ArrayList<ArrayList<Integer>> l = new ArrayList<>(); for(int i=0;i<n;i++){ ArrayList<Integer> temp = new ArrayList<>(); int d=in.nextInt(); for(int x=0;x<d;x++){ temp.add(in.nextInt()); } l.add(temp); } int q=in.nextInt(); for(int i =0;i<q;i++){ int a=in.nextInt(); int b=in.nextInt(); try{ System.out.println(l.get(a-1).get(b-1)); }catch(Exception e){ System.out.println("ERROR!"); } } in.close();
+ 0 comments Here are the solution of Java Arraylist Hacker Rank Solution
+ 0 comments public static void main(String[] args) { Scanner sc =new Scanner( System.in) ; int lines =sc.nextInt() ; ArrayList array_list = new ArrayList() ; for (int i=0 ;i < lines;i++ ){ int colLineItem = sc.nextInt(); array_list.add(new ArrayList<>()); for(int y =0 ;y
} catch (Exception e) { System.out.println("ERROR!"); } } }
}
+ 0 comments public static void main(String[] args) { Scanner sc =new Scanner( System.in) ; int lines =sc.nextInt() ; ArrayList array_list = new ArrayList() ; for (int i=0 ;i < lines;i++ ){ int colLineItem = sc.nextInt(); array_list.add(new ArrayList<>()); for(int y =0 ;y
} catch (Exception e) { System.out.println("ERROR!"); } } }
}
+ 0 comments 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. */ List<List<Integer>> listOfArray = new ArrayList<>(); Scanner s= new Scanner(System.in); int n =s.nextInt(); for(int i=0;i<n;i++){ int d=s.nextInt(); List<Integer> listf = new ArrayList<Integer>() ; for(int j=0;j<d;j++){ listf.add(s.nextInt()); } listOfArray.add(listf); } // System.out.println(listOfArray); int q =s.nextInt(); for(int i=0;i<q;i++){ int x= s.nextInt(); int y =s.nextInt(); try{ System.out.println( listOfArray.get(x-1).get(y-1)); } catch(Exception ex){ System.out.println("ERROR!"); } } s.close(); }
}
Sort 657 Discussions, By:
Please Login in order to post a comment