数组倒置

有这样一个题目,给出了一个一维整型数组,要求对其进行倒置后然后输出!有可能以下的解决办法,如果有更好的解决办法欢迎回复说明!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public static void reverse(int x[]){
int foot=0;
int head=0;
if(x.length%2==0){
foot=x.length/2;
head=foot-1;
for(int i=0; i int temp=x[head];
x[head]=x[foot];
x[foot]=temp;
head--;
foot++;
}
}else{
foot=x.length/2;
head=foot;
for(int i=0; i int temp=x[head];
x[head]=x[foot];
x[foot]=temp;
head--;
foot++;
}
}
}