二维互换

package com.bjsunyuhuan.test;

public class TestDemos {  public static void main(String[] args) {   int data[][]=new int[][]{{1,2,3},{4,5,6},{7,8,9}};   reverse(data);      print(data);       }

 private static void reverse(int[][] data) {    for(int x=0;x<data.length;x++){     for(int y=0;y<data[x].length;y++){       int t=data[x][y];       data[x][y]=data[y][x];       data[y][x]=t;     }    }  }

 private static void print(int[][] data) {   for(int x=0;x<data.length;x++){     for(int y=0;y<data[x].length;y++){      System.out.print(data[x][y]+"、");     }     System.out.println();   }   System.out.println();  }      /*public static void main(String[] args) {   //将数组倒序   int data[]=new int[]{1,2,3,4,5,6};//将数组静态化处理   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();  }   */   }

总结很重要哦 方法得当,坚持会有奇迹哦
原文地址:https://www.cnblogs.com/sunyuhuan/p/7250631.html