I believe the code works but the tester code isn't and I'm not sure why. I'm trying to swap the first and last value in an array.
public class ArrayMethods {
private int[] values;
public ArrayMethods(int[] initialValues) {
values = initialValues;
}
public void swapFirstAndLast() {
int lastvalplace = values.length;
int firstval = values[0];
values[0] = values[lastvalplace];
values[lastvalplace] = firstval;
}
public static void main(String[] args) {
ArrayMethods initialValues = new ArrayMethods(int[] 50, 32, 4, 9, 2);
swapFirstAndLast = new swapFirstAndLast(values);
}
}
array[array.length - 1](notarray[array.length]like in your code)