1int lastElement = values[values.length-1];
2values[values.length-1] = values[0];
3values[0] = lastElement;
4
1public class ArrayMethods {
2
3private int[] values;
4public ArrayMethods(int[] initialValues) {
5values = initialValues;
6}
7public void swapFirstAndLast() {
8int lastvalplace = values.length;
9int firstval = values[0];
10values[0] = values[lastvalplace];
11values[lastvalplace] = firstval;
12}
13
14public static void main(String[] args) {
15ArrayMethods initialValues = new ArrayMethods(int[] 50, 32, 4, 9, 2);
16swapFirstAndLast = new swapFirstAndLast(values);
17}
18
19}
20