zoukankan      html  css  js  c++  java
  • 今日头条--二维数组矩形输出

    public class PrintArrayLoop {

    public static void printArrayForLoopWay(int[][] arr) {
    if (arr == null || arr.length == 0 || arr[0] == null || arr[0].length == 0) {
    return;
    }
    int row = arr.length;
    int column = arr[0].length;
    int number = row > column ? (column - 1) : (row - 1);
    int i = 0, j = 0;
    for (int k = 0; k < number; k++) {
    if (j > column - 1 - k) {
    return;
    }
    for (j = k; j <= column - 1 - k; j++) {
    System.out.printf(arr[i][j] + " ");
    }
    j--;
    i = k + 1;
    if (i > row - k - 1) {
    return;
    }
    for (; i <= row - k - 1; i++) {
    System.out.printf(arr[i][j] + " ");
    }
    i--;
    j = column - k - 2;
    if (j < k) {
    return;
    }
    for (; j >= k; j--) {
    System.out.printf(arr[i][j] + " ");
    }
    j++;
    i = row - 2 - k;
    if (i < k + 1) {
    return;
    }
    for (; i >= k + 1; i--) {
    System.out.printf(arr[i][j] + " ");
    }
    i++;
    j++;
    }
    }

    public static void main(String [] args){
    int[][] arr=
    {{1,2,3,4,5,6},{11,12,13,14,15,16},{21,22,23,24,25,26},{31,32,33,34,35,36},{41,42,43,44,45,46},{51,52,53,54,55,56}};
    printArrayForLoopWay(arr);
    }
    }
  • 相关阅读:
    ASP.NET 下载文件方式
    分享各大平台接口(空间,微博)
    BitmapToASCii
    C#操作进程(Process)
    Config ConnectionStrings
    Import Excel void (NPOI)
    C# Serialize
    C# 属性
    调用存储过程的方法
    Redis配置与安装
  • 原文地址:https://www.cnblogs.com/mlz-2019/p/9516886.html
Copyright © 2011-2022 走看看