>数字模式(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 = 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 = 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) 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) 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 = 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 = 1; row--) { for (int col = 1; col = 1; row--) { for (int col = 1; col = 1; row--) { for (int col = 1; col = 1; row--) { for (int col = 1; col = 1; row--) { for (int col = 1; col = 1; row--) { for (int col = 1; col <= row; col++) System.out.print("* "); System.out.println(); } }}output:* * * * * * * * * * * * * * *
以上就是用于循环编号模式:的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/190617.html
微信扫一扫
支付宝扫一扫