for巢狀迴圈"大圈套小圈"思想
阿新 • • 發佈:2019-01-28
package zhang.com; public class Tuxing { public static void main(String[] args) { // Test1(); // Test2(); // Test3(); // Test4(); } /** * ****** ***** **** *** ** * */ private static void Test4() { for (int i = 1; i <= 6; i++) { for (int j = 1; j < i; j++) { System.out.print(" "); } for (int z = i; z <= 6; z++) { // * * * * * * // * * * * * // * * * * // * * * // * * // * // System.out.print("* "); System.out.print("*");// } System.out.println(); } } /** * ** *** **** ***** ****** */ private static void Test3() { for (int i = 1; i <= 6; i++) { for (int j = i; j < 6; j++) { System.out.print(" "); } for (int z = 1; z <= i; z++) { // * // * * // * * * // * * * * // * * * * * // * * * * * * // System.out.print("* "); System.out.print("*"); } System.out.println(); } } /** ****** ***** **** *** ** * */ private static void Test2() { for (int i = 1; i <= 6; i++) { for (int j = i; j <= 6; j++) { System.out.print("* "); } System.out.println(); } } /** * ** *** **** ***** ****** */ private static void Test1() { for (int i = 1; i <= 6; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(); } } }