You are viewing a single comment's thread. Return to all comments →
a bit verbose but full working
ArrayList<ArrayList<Integer>> righe = new ArrayList<ArrayList<Integer>>(0); Scanner s = new Scanner(System.in); int index = s.nextInt(); for (int i=0; i<=index; i++) { String line = s.nextLine(); if (i != 0) { String[] lineAsArray = line.split(" "); ArrayList<Integer> tempIntegerList = new ArrayList<Integer>(0); for (String numberAsString : lineAsArray) tempIntegerList.add(Integer.parseInt(numberAsString)); righe.add(tempIntegerList); } } index = s.nextInt(); for (int i=0; i<=index; i++) { String[] tempCoordinates = s.nextLine().split(" "); if (i != 0) { ArrayList<Integer> coordinates = new ArrayList<Integer>(0); for (String es : tempCoordinates) coordinates.add(Integer.parseInt(es)); try { System.out.println(righe.get(coordinates.get(0) - 1).get(coordinates.get(1))); } catch (Exception err) { System.out.println("ERROR!"); } } }
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 →
a bit verbose but full working