How do I write a method, that has a parameter integer representing the index, and returns the value the array holds at the specified index. But the array being used has been generated by a previous method. So far I have this:
public static int get(int var) {
int[] result = constructArray(arrayA,array B);
return result[var];
}
The main method looks like
public static void main(final String[] args) {
int[]result = constructArray(arrayA,arrayB);
System.out.println(Arrays.toString(result));
int variable = get(2);
System.out.println(variable);
}
The method constructArray constructs a different array each time it is called, so when I call the get method I want to use the array that has already been constructed. How can I achieve this?