日期:2014-05-20 浏览次数:20803 次
public class TwoArray { /** * @author 耿旭 * @2012-8-22下午3:22:21 * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int[][] array = {{1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9}}; System.out.println("-------------------------------------------------"); for(int i = 0 ; i<array.length; i++){ for(int j=0;j<array[i].length; j++){ System.out.print(array[i][j]+",\t"); } System.out.println(); } int[][] array1 = zhuan(array); System.out.println("--------------------逆时针90度1次----------------------"); for(int i = 0 ; i<array1.length; i++){ for(int j=0;j<array1[i].length; j++){ System.out.print(array1[i][j]+",\t"); } System.out.println(); } int[][] array2 = zhuan(array1); System.out.println("----------------逆时针90度2次-----------------------"); for(int i = 0 ; i<array2.length; i++){ for(int j=0;j<array2[i].length; j++){ System.out.print(array2[i][j]+",\t"); } System.out.println(); } int[][] array3 = zhuan(array2); System.out.println("----------------逆时针90度3次-----------------------"); for(int i = 0 ; i<array3.length; i++){ for(int j=0;j<array3[i].length; j++){ System.out.print(array3[i][j]+",\t"); } System.out.println(); } int[][] array4 = zhuan(array3); System.out.println("----------------逆时针90度4次-----------------------"); for(int i = 0 ; i<array4.length; i++){ for(int j=0;j<array4[i].length; j++){ System.out.print(array4[i][j]+",\t"); } System.out.println(); } } static int[][] zhuan(int[][] rray){ int[][] buffer =new int[rray.length][rray[1].length];//副本 for(int i = 0 ; i<buffer.length; i++){ for(int j=0;j<buffer[i].length; j++){ buffer[i][j]=rray[j][buffer.length-1-i]; } } return buffer; } }