How would I switch corresponding elements in an array (Ex: First with last, Second with one before last) using a loop. I've worked out the code using a loop, but it doesn't give the desired result in Eclipse.
int[] a = {1, 2, 3, 4, 5};
int k = 0;
int temp = 0;
while(k < a.length)
{
temp = a[k];
a[k] = a[a.length - 1 - k];
a[a.length - 1 - k] = temp;
k++;
}
Assume that you don't know the values in the array or how long it is.