当前位置: 代码迷 >> J2SE >> 刚刚想个挺有意思的程序
  详细解决方案

刚刚想个挺有意思的程序

热度:8297   发布时间:2013-02-25 00:00:00.0
刚想个挺有意思的程序
定义一个n*n的二维数组
  然后 让数组里的 每一个值 都进行 180°旋转
  输出一下~~~
 

------解决方案--------------------------------------------------------
Java code
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;    }}
  相关解决方案