打印旋转矩阵

来源:互联网 发布:landsat5数据预处理 编辑:程序博客网 时间:2024/06/03 14:53
package com.zhuyu_deng.test;import java.util.Stack;public class Test{private static void printRotMatrix(int a[][]){int n = a.length;for (int i = 0; i < n / 2; ++i){int fir = i;int end = n-1-i;for (int j = fir; j <= end; ++j)System.out.print(a[fir][j] + " ");for (int j = fir+1; j <= end; ++j)System.out.print(a[j][end] + " ");for (int j = end-1; j >= fir; --j)System.out.print(a[end][j] + " ");for (int j = end-1; j > fir; --j)System.out.print(a[j][fir] + " ");}if (n % 2 == 1)System.out.print(a[n/2][n/2] + " ");}private static void makeRotMatrix(int[][] a){}public static void main(String args[]){// int[] a = {-2,11,-4,13,-5,-2};int[][] b = { { 0, -2, -7, 0 }, { 9, 2, -6, 2 }, { -4, 1, -4, 1 },{ -1, 8, 0, -2 } };int[][] matrix = { { 2, 3, 4, 1 }, { 1, 1, 3, 9 }, { 2, 2, 3, 1 },{ 2, 2, 3, 1 } };char a[][] = new char[][] { { 'W', 'B', 'W', 'W', 'B', 'W' },{ 'B', 'B', 'W', 'W', 'B', 'W' },{ 'W', 'B', 'B', 'B', 'W', 'B' },{ 'W', 'B', 'W', 'W', 'B', 'B' } };int x[][] = { {1,2,3,4},              {12,13,14,5},              {11,16,15,6},              {10,9,8,7},            };int xy[][] = { {1,2,3},{8,9,4},{7,6,5}};printRotMatrix(x);}}

原创粉丝点击