1. 程式人生 > >java之中的陣列聯絡(一維轉置)

java之中的陣列聯絡(一維轉置)

public class TestString{
public static void main(String args[]){
int data[] = new int [] {1,2,3,4,5,6} ;
print(data) ;
reverse(data);
print(data);
}
public static void reverse(int temp[]){
int head = 0 ;
int tail = temp.length - 1;
int center = temp.length / 2;
for(int x = 0 ; x <= center; x++){
int t = temp[head];
temp[head] = temp[tail];
temp[tail] = t;
head ++ ;
tail --;
}
}
public static void  print (int temp[]){
for (int x = 0 ; x < temp.length ; x++){
System.out.print (temp[x] + "、") ;

}
System.out.println() ;
}
}