Just in case, I attached all the code so that it would not be taken out of context for sure.

The get method returns the i-th element from the array, which is listed in the list а under the number k. Return in the get method body produces this error.

I understand that something is wrong, but I cannot identify the exact root of the error

I would be grateful for any advice or hint.

I apologize, the code did not want to be correctly inserted, and I'm completely new here

public class Main implements Cloneable { public static void main(String[] args){ List<int[]> a = new ArrayList<int[]>(); Scanner reader = new Scanner(System.in); int n; for( ; ; ) { n = reader.nextInt(); if(n<100000) break; } int[] a0 = new int[n]; for (int i = 0; i < n; i++) a0[i] = reader.nextInt(); a.add(a0); int m; for( ; ; ) { m = reader.nextInt(); if(m<100000) break; } for (int i = 0; i < m+1; i++){ String request = reader.nextLine(); if (request=="create") { int version = reader.nextInt(); int position = reader.nextInt(); int symbol = reader.nextInt(); create(a, position, version, symbol); } else if (request=="get") { int version = reader.nextInt(); int position = reader.nextInt(); System.out.println(get(a, position, version)); } } } public static void create(List<int[]> a, int position, int version, int symbol) { a.add((a.get(version)).clone()); int last=a.size(); a.get(last)[position]=symbol; } public static int get(List<int[]> a, int position, int version) { return a.get((version)[position]); } } 
  • Insert the code, select it in its entirety, press the button with {} , the script will insert an indent in 4 spaces into each line (or remove if all lines start with such an indent). - zRrr
  • on the question - you need a.get(version)[position] , because get returns the array in the list. - zRrr

1 answer 1

Error in get() method. Correctly:

 public static int get(List<int[]> a, int position, int version) { return a.get(version)[position]; }