Topic
"之"字形打印矩阵
Java code
Package com.lizhouwei.chapter8;/** * @Description: "It" glyph print Matrix * @Author: Lizhouwei * @CreateDate: 2018/4/28 22:53 * @Modify By: * @ModifyDate: */public class Chapter8_3 {public void Printmatrixzigzag (int[][] matrix) {int TR = 0; int TC = 0; int DR = 0; int DC = 0; int endr = matrix.length-1; int ENDC = matrix[0].length-1; Boolean utod = false; while (tr <= endr) {printzigzag (Matrix, Utod, TR, DR, TC, DC); TR = TC = = Endc? TR + 1:tr; TC = TC = = ENDC? TC:TC + 1; DC = DR = = Endr? DC + 1:DC; Dr = Dr = = Endr? DR:DR + 1; Utod =! Utod; }} public void Printzigzag (int[][] Matrix, boolean utod, int tR, int dR, int tC, int dC) {if (Utod) { while (TR! = dr+1) {System.out.print (matrix[tr++][tc--]+ ""); }} else {while (TR! = dr+1) {System.out.print (matrix[dr--][dc++]+ ""); }} System.out.println (); }//test public static void main (string[] args) {chapter8_3 chapter = new Chapter8_3 (); int[][] Matrix = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; Chapter.printmatrixzigzag (matrix); }}
Results
"Programmer Code Interview Guide" eighth chapter array and matrix Problem "" of the glyph print matrix