forloop-pattern for num 1 2 3 4 5 6 7 8 9 & star pattern

program: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();
}
}
}
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();
        }

    }

}
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(); } } }

Enter fullscreen mode Exit fullscreen mode

program: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();
}
}
}
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();

        }
    }
}
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(); } } }

Enter fullscreen mode Exit fullscreen mode

program:3

package afterfeb13;
public class forpattern12345 {
public static void main(String[] args) {
for (int row = 1; row <= 5; row++) {
for (int col = 1; col <= row; col++) {
System.out.print("* ");
}
System.out.println();
}
}
}
package afterfeb13;

public class forpattern12345 {
    public static void main(String[] args) {

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

            }
            System.out.println();

        }

    }
}
package afterfeb13; public class forpattern12345 { public static void main(String[] args) { for (int row = 1; row <= 5; row++) { for (int col = 1; col <= row; col++) { System.out.print("* "); } System.out.println(); } } }

Enter fullscreen mode Exit fullscreen mode

原文链接:forloop-pattern for num 1 2 3 4 5 6 7 8 9 & star pattern

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享
Have faith in your dreams and someday your rainbow will come smiling through.
请对梦想充满信心,总有一天属于你的彩虹会在天空微笑
评论 抢沙发

请登录后发表评论

    暂无评论内容