Image

Ok. I am stumped on a codelab problem for my class. Here it is:

Given  an array  a and two other int variables , k and temp , write a loop that reverses the elements  of the array .



I have written the following code:
temp = 0;
for (k = a.length-1; k >= 0; k--)
{
a[a.length - 1 - k] = temp;
a[k] = temp;
}


I also tried this:


temp = 0;
for (k= 0; k < a.length; k++)
{
temp = a[k];
a[a.length - k-1]=temp;
}



It doesn't give me any reasons for why it doesn't work, just simply says it's invalid, but I can't see why? It's not b/c I'm missing a print statement b/c I tried adding that. So where am I going wrong?