zoukankan      html  css  js  c++  java
  • 二维数组横竖倾斜遍历

    /**
    程序名称:二维数组横竖倾斜遍历
    */
    class array8 
    {
        public static void main(String[] args) 
        {
            int[][] a = new int[9][9];
            for(int i = 0; i < 9; i++)
            {
                for(int j = 0; j < 9; j++)
                {
                    a[i][j] = i;
                }
            }
    
            for(int i = 0; i < 9; i++)
            {
                for(int j = 0; j < 9; j++)
                {
                    System.out.print(a[i][j]);
                }
                System.out.println();
            }
    
    
        
    
            for(int i = 0; i < 17; i++)
            {
                for(int j = 0; j < 9; j++)
                {
                    if(((i - j) >= 0)&&((i - j) < 9))
                    {
                        System.out.print(a[j][i-j]+" ");
                    }
                }
                System.out.println();
            }
            System.out.println("****************************");
    
            for(int i = -8; i < 9; i++)
            {
                for(int j = 0; j < 9; j++)
                {
                    if(((i + j) >= 0)&&((i + j)< 9))
                    {
                        System.out.print(a[j][i+j]+" ");
                    }
                    
                }
                System.out.println();
            }
        }
    }
    
    /**
    *输出结果:
    000000000
    111111111
    222222222
    333333333
    444444444
    555555555
    666666666
    777777777
    888888888
    0
    0 1
    0 1 2
    0 1 2 3
    0 1 2 3 4
    0 1 2 3 4 5
    0 1 2 3 4 5 6
    0 1 2 3 4 5 6 7
    0 1 2 3 4 5 6 7 8
    1 2 3 4 5 6 7 8
    2 3 4 5 6 7 8
    3 4 5 6 7 8
    4 5 6 7 8
    5 6 7 8
    6 7 8
    7 8
    8
    ***********************
    8
    7 8
    6 7 8
    5 6 7 8
    4 5 6 7 8
    3 4 5 6 7 8
    2 3 4 5 6 7 8
    1 2 3 4 5 6 7 8
    0 1 2 3 4 5 6 7 8
    0 1 2 3 4 5 6 7
    0 1 2 3 4 5 6
    0 1 2 3 4 5
    0 1 2 3 4
    0 1 2 3
    0 1 2
    0 1
    0
    请按任意键继续. . .
    
    
    
    
    */
  • 相关阅读:
    Git 中 .gitignore 的配置语法
    DMX512协议
    k8s 报错总结
    yum 源配置
    docker 安装 docker-compose
    docker 搭建 Harbor 仓库
    linux 远程执行命令
    远程从服务器A拷贝文件到服务器B
    docker 搭建私服仓库
    awk和xargs清除docker 容器、镜像
  • 原文地址:https://www.cnblogs.com/flay/p/3321653.html
Copyright © 2011-2022 走看看