- 利用数组角标来置换操作
class ArrayUtil {
// 数组转置操作,左右排序颠倒操作;
public static void reverse(int data []){
int center = data.length / 2;
int head = 0;
int tail = data.length - 1;
for(int x = 0; x < center ; x++){
int temp = data[head];
data[head] = data[tail];
data[tail] = temp;
head++;
tail--;
}
}
public static void printArray(int temp []){
for(int x = 0;x < temp.length;x++){
System.out.print(temp[x] + ",");
}
}
}
public class HelloWorld {
public static void main(String[] args){
int data [] = new int [] {1,2,3,4,5,6};
ArrayUtil arrayUtil = new ArrayUtil();
arrayUtil.printArray(data);
arrayUtil.reverse(data);
System.out.println();
arrayUtil.printArray(data);
}
}
标签:head,temp,转置,6.7,int,tail,数组,data,public
From: https://www.cnblogs.com/pansidong/p/17456691.html