I'm given the following method that is supposed to exchange the first two elements of the array that is passed as an argument to the method:
public void exchange(int[] a){
int c[] = new int[a.length];
c[0] = a[1];
c[1] = a[0];
for(int i = 2; i < a.length; i++)
c[i] = a[i];
a = c;
}
Why doesn't this method work as intended?
At first I thought i was because c's scope is limited to the method, a reference assignment a = c would not have any effect outside that function, but the method does not work even if I use c as an additional parameter. Can anybody tell me why this method doesn't work, please?