登录
首页 >  文章 >  java教程

forloop-pattern用于数字;星形图案

来源:dev.to

时间:2025-02-17 13:28:01 275浏览 收藏

一分耕耘,一分收获!既然打开了这篇文章《forloop-pattern用于数字;星形图案》,就坚持看下去吧!文中内容包含等等知识点...希望你能在阅读本文后,能真真实实学到知识或者帮你解决心中的疑惑,也欢迎大佬或者新人朋友们多留言评论,多给建议!谢谢!

程序:1

>

package afterfeb13;

public class patternfornumber {
    public static void main(string[] args) {
        // number1();
        // number2();
        // number3();
        // number4();
        // number5();
        // number6();
        // number7();
        // number8();
        number9();

    }

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

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

            }
            system.out.println();
        }

    }

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

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

            }
            system.out.println();
        }

    }

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

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

            }
            system.out.println();
        }

    }

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

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

            }
            system.out.println();
        }

    }

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

            }
            system.out.println();
        }

    }

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

            }
            system.out.println();
        }

    }

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

            }
            system.out.println();
        }

    }

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

            }
            system.out.println();
        }

    }

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

            }
            system.out.println();
        }

    }

}

程序:2

>

package afterfeb13;

//54321 star
public class forpatternstar {
    public static void main(string[] args) {

        for (int row = 5; row >= 1; row--) {
            for (int col = 1; col <= row; col++) {
                system.out.print("* ");

            }
            system.out.println();

        }
    }
}
程序:3

> 2777732522112

今天关于《forloop-pattern用于数字;星形图案》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:dev.to 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>