This reverses the source array by an in place technique. Basically, you are ONLY allowed to use the source array and cannot create another one.
public static void reverseArrayInPlace(int [] source){
for(int col=0; col<source.length/2; ++col){
int temp=source[col];
source[col]=source[(source.length-1)-col];
source[(source.length-1)-col]=temp;
}
}
//initially; 10 20 30 40 50 60
// col=0; 60 20 30 40 50 10
// col=1; 60 50 30 40 20 10
// col=2; 60 50 40 30 20 10
// col=3; 60 50 30 40 20 10
// col=4; 60 20 30 40 50 10
// col=5; 10 20 30 40 50 60
This is why we give the condition col<(source.length/2)
, if it went up to col<source.length
then it would be arranged in the same manner it was before i.e, it wouldn't reverse. Try it both ways to see it yourself.