java的二维转换

来源:互联网 发布:在淘宝免费买东西app 编辑:程序博客网 时间:2024/06/03 08:16
public class TestString2{
public static void main(String args[]){
int data [][] = new int [][] {{1,2,3},{4,5,6},{7,8,9}};
print(data);
         reverse(data) ;
print(data);
}
public static void reverse(int temp[][]){
   for (int x = 0 ; x <temp .length/2 ; x++){
for (int y  = 0 ; y <temp[x].length ;y++){
int t = temp[x][y] ;
temp[x][y] = temp[y][x] ;
temp[y][x] = t ;
}
}
}
public static void print (int temp[][]){
for (int x = 0 ; x < temp.length ;x++){
for(int y = 0 ; y < temp[x].length ;y++){
System.out.print(temp[x][y] + "、");
}
 
System.out.println() ;
}
System.out.println() ;
}
}
0 0
原创粉丝点击