0

0

用于循环编号模式:

霞舞

霞舞

发布时间:2025-02-16 11:06:28

|

576人浏览过

|

来源于dev.to

转载

>数字模式(1to9):

package b1;

public class npattern {

    public static void main(string[] args) {
        // npattern1();
        // npattern2();
        // npattern3();
        // npatern4();
        // npattern5();
        // npattern6();
        // npattern7();
        // npattern8();
        // npattern9();
        npattern10();

    }

    private static void npattern10() {
        for (int row = 1; row <= 9; row++) {
            for (int col = 1; col <= 9; col++) {
                if (col == 3 || col == 9 || col == 1)
                    system.out.print("* ");
                else if (row == 1 && col >= 3 || row == 9 && col >= 3)
                    system.out.print("* ");
                else
                    system.out.print("  ");
            }
            system.out.println();
        }

    }
output:

*   * * * * * * * 
*   *           * 
*   *           * 
*   *           * 
*   *           * 
*   *           * 
*   *           * 
*   *           * 
*   * * * * * * * 


    private static void npattern9() {
        for (int row = 1; row <= 9; row++) {
            for (int col = 1; col <= 9; col++) {
                if (row == 9 || row == 1 || col == 9)
                    system.out.print("* ");
                else if (row == 5 || col == 1 && row <= 5)
                    system.out.print("* ");
                else
                    system.out.print("  ");
            }
            system.out.println();
        }

    }
output:

* * * * * * * * * 
*               * 
*               * 
*               * 
* * * * * * * * * 
                * 
                * 
                * 
* * * * * * * * * 



    private static void npattern8() {
        for (int row = 1; row <= 9; row++) {
            for (int col = 1; col <= 9; col++) {
                if (row == 5 || row == 1 || row == 9)
                    system.out.print("* ");
                else if (col == 1 || col == 9)
                    system.out.print("* ");
                else
                    system.out.print("  ");
            }
            system.out.println();
        }
    }
output:

* * * * * * * * * 
*               * 
*               * 
*               * 
* * * * * * * * * 
*               * 
*               * 
*               * 
* * * * * * * * * 


    private static void npattern7() {
        for (int row = 1; row <= 9; row++) {
            for (int col = 1; col <= 9; col++) {
                if (row == 1 || row + col == 10)
                    system.out.print("* ");

                else
                    system.out.print("  ");
            }
            system.out.println();
        }

    }
output:

* * * * * * * * * 
              *   
            *     
          *       
        *         
      *           
    *             
  *               
*          

    private static void npattern6() {
        for (int row = 1; row <= 9; row++) {
            for (int col = 1; col <= 9; col++) {
                if (row == 5 || row == 1 || row == 9)
                    system.out.print("* ");
                else if (col == 1 || col == 9 && row >= 5)
                    system.out.print("* ");
                else
                    system.out.print("  ");
            }
            system.out.println();
        }
    }
output:

* * * * * * * * * 
*                 
*                 
*                 
* * * * * * * * * 
*               * 
*               * 
*               * 
* * * * * * * * * 


    private static void npattern5() {
        for (int row = 1; row <= 9; row++) {
            for (int col = 1; col <= 9; col++) {
                if (row == 5 || row == 1 || row == 9)
                    system.out.print("* ");
                else if (col == 1 && row <= 5 || col == 9 && row >= 5)
                    system.out.print("* ");
                else
                    system.out.print("  ");
            }
            system.out.println();
        }

    }
output:

* * * * * * * * * 
*                 
*                 
*                 
* * * * * * * * * 
                * 
                * 
                * 
* * * * * * * * * 


    private static void npatern4() {

        for (int row = 1; row <= 9; row++) {
            for (int col = 1; col <= 9; col++) {
                if (row == 5 || col == 5)
                    system.out.print("* ");
                else if (row + col == 6 && row <= 5)
                    system.out.print("* ");
                else
                    system.out.print("  ");
            }
            system.out.println();
        }
    }
output:

        *         
      * *         
    *   *         
  *     *         
* * * * * * * * * 
        *         
        *         
        *         
        * 

    private static void npattern3() {
        for (int row = 1; row <= 9; row++) {
            for (int col = 1; col <= 9; col++) {
                if (row == 9 || row == 5 || row == 1)
                    system.out.print("* ");
                else if (col == 9 && row <= 5 || col == 9 && row >= 5)
                    system.out.print("* ");
                else
                    system.out.print("  ");
            }
            system.out.println();
        }

    }
output:

* * * * * * * * * 
                * 
                * 
                * 
* * * * * * * * * 
                * 
                * 
                * 
* * * * * * * * * 


    private static void npattern2() {
        for (int row = 1; row <= 9; row++) {
            for (int col = 1; col <= 9; col++) {
                if (row == 9 || row == 5 || row == 1)
                    system.out.print("* ");
                else if (col == 1 && row >= 5 || col == 9 && row <= 5)
                    system.out.print("* ");
                else
                    system.out.print("  ");
            }
            system.out.println();
        }
    }
output:

* * * * * * * * * 
                * 
                * 
                * 
* * * * * * * * * 
*                 
*                 
*                 
* * * * * * * * * 


    private static void npattern1() {
        for (int row = 1; row <= 9; row++) {
            for (int col = 1; col <= 9; col++) {
                if (row == 9 || col == 5 || col + row == 6 && row <= 4)
                    system.out.print("* ");
                else
                    system.out.print("  ");
            }
            system.out.println();
        }
    }
}

output:

        *         
      * *         
    *   *         
  *     *         
        *         
        *         
        *         
        *         
* * * * * * * * * 


星数和数字模式:>

package B1;

public class NSpattern {

    public static void main(String[] args) {
        pattern();
        // pattern1();
        // pattern2();
        // pattern3();
        // pattern4();
        // pattern5();
        // pattern6();

    }

    private static void pattern() {
        for (int row = 1; row <= 5; row++) {
            for (int col = 1; col <= row; col++)
                System.out.print("* ");

            System.out.println();
        }

    }
output:
* 
* * 
* * * 
* * * * 
* * * * * 


    private static void pattern6() {
        for (int row = 5; row >= 1; row--) {
            for (int col = 1; col <= row; col++)
                System.out.print(row + col + " ");
            System.out.println();
        }

    }
output:

6 7 8 9 10 
5 6 7 8 
4 5 6 
3 4 
2 


    private static void pattern5() {
        for (int row = 5; row >= 1; row--) {
            for (int col = 1; col <= row; col++)
                System.out.print(row / col + " ");
            System.out.println();
        }
    }
output:

5 2 1 1 1 
4 2 1 1 
3 1 1 
2 1 
1 


    private static void pattern4() {
        for (int row = 5; row >= 1; row--) {
            for (int col = 1; col <= row; col++)
                System.out.print(row * col + " ");
            System.out.println();
        }
    }
output:

5 10 15 20 25 
4 8 12 16 
3 6 9 
2 4 
1



    private static void pattern3() {
        for (int row = 5; row >= 1; row--) {
            for (int col = 1; col <= row; col++)
                System.out.print(col + " ");
            System.out.println();
        }
    }
output:

1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 



    private static void pattern2() {
        for (int row = 5; row >= 1; row--) {
            for (int col = 1; col <= row; col++)
                System.out.print(row + " ");
            System.out.println();
        }
    }
output:

5 5 5 5 5 
4 4 4 4 
3 3 3 
2 2 
1 

    private static void pattern1() {
        for (int row = 5; row >= 1; row--) {
            for (int col = 1; col <= row; col++)
                System.out.print("* ");
            System.out.println();
        }

    }

}
output:

* * * * * 
* * * * 
* * * 
* * 
* 

相关专题

更多
c++ 根号
c++ 根号

本专题整合了c++根号相关教程,阅读专题下面的文章了解更多详细内容。

57

2026.01.23

c++空格相关教程合集
c++空格相关教程合集

本专题整合了c++空格相关教程,阅读专题下面的文章了解更多详细内容。

57

2026.01.23

yy漫画官方登录入口地址合集
yy漫画官方登录入口地址合集

本专题整合了yy漫画入口相关合集,阅读专题下面的文章了解更多详细内容。

237

2026.01.23

漫蛙最新入口地址汇总2026
漫蛙最新入口地址汇总2026

本专题整合了漫蛙最新入口地址大全,阅读专题下面的文章了解更多详细内容。

393

2026.01.23

C++ 高级模板编程与元编程
C++ 高级模板编程与元编程

本专题深入讲解 C++ 中的高级模板编程与元编程技术,涵盖模板特化、SFINAE、模板递归、类型萃取、编译时常量与计算、C++17 的折叠表达式与变长模板参数等。通过多个实际示例,帮助开发者掌握 如何利用 C++ 模板机制编写高效、可扩展的通用代码,并提升代码的灵活性与性能。

17

2026.01.23

php远程文件教程合集
php远程文件教程合集

本专题整合了php远程文件相关教程,阅读专题下面的文章了解更多详细内容。

103

2026.01.22

PHP后端开发相关内容汇总
PHP后端开发相关内容汇总

本专题整合了PHP后端开发相关内容,阅读专题下面的文章了解更多详细内容。

73

2026.01.22

php会话教程合集
php会话教程合集

本专题整合了php会话教程相关合集,阅读专题下面的文章了解更多详细内容。

81

2026.01.22

宝塔PHP8.4相关教程汇总
宝塔PHP8.4相关教程汇总

本专题整合了宝塔PHP8.4相关教程,阅读专题下面的文章了解更多详细内容。

70

2026.01.22

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
10分钟--Midjourney创作自己的漫画
10分钟--Midjourney创作自己的漫画

共1课时 | 0.1万人学习

Midjourney 关键词系列整合
Midjourney 关键词系列整合

共13课时 | 0.9万人学习

AI绘画教程
AI绘画教程

共2课时 | 0.2万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号