Topic
转圈打印矩阵
Java code
Package com.lizhouwei.chapter8;/** * @Description: Circular print Matrix * @Author: Lizhouwei * @CreateDate: 2018/4/28 21:52 * @Modify by : * @ModifyDate: */public class Chapter8_1 {public void Printmatrix (int[][] matrix) {int TR = 0; int TC = 0; int DR = matrix.length-1; int DC = matrix[0].length-1; while (TR < DR) {Printltor (Matrix, tr++, DR, TC, DC); Printutod (Matrix, TR, DR, TC, dc--); Printrtol (Matrix, TR, DR--, TC, DC); Printdtou (Matrix, TR, DR, tc++, DC); }} private void Printltor (int[][] Matrix, int tR, int dR, int tC, int dc) {while (TC <= DC) { System.out.print (matrix[tr][tc++] + ""); } System.out.println (); } private void Printutod (int[][] Matrix, int tR, int dR, int tC, int dC) {while (TR <= DR) {Syst Em.out.print (MATRIX[TR++][DC] + ""); } System.out.println (); } private void PrintrtOL (int[][] Matrix, int tR, int dR, int tC, int dC) {while (TC <= DC) {System.out.print (matrix[dr][d c--] + ""); } System.out.println (); } private void Printdtou (int[][] Matrix, int tR, int dR, int tC, int dC) {while (TR <= DR) {Syst Em.out.print (MATRIX[DR--][TC] + ""); } System.out.println (); }//test public static void main (string[] args) {chapter8_1 chapter = new Chapter8_1 (); int[][] Matrix = {{1, 2, 3, 4, 5}, {14, 15, 16, 17, 6}, {13, 20, 19, 18, 7}, {12, 11, 10, 9, 8}}; Chapter.printmatrix (matrix); }}
Results
Code interview guide for Programmers eighth chapter array and matrix problems circle print matrix