Code interview guide for Programmers eighth chapter array and matrix problems circle print matrix

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.