嵌套

大圈套小圈:

 1 package cn.itcast.day04_for;
 2 
 3 public class test1 {
 4 
 5     /*
 6      * 案例一:
 7      *    *****
 8      *    *****
 9      *    *****
10      *    *****
11      */
12 
13     public static void main(String[] args) {
14         for (int i = 0; i < 5; i++) {
15             for (int j = 0; j < 5; j++) {
16                 System.out.print("*");
17             }
18             System.out.println();
19         }
20     }
21 }
 1 package cn.itcast.day04_for;
 2 
 3 public class test2 {
 4 
 5     public static void main(String[] args) {
 6 
 7         /*
 8          * 案例二:
 9          *  *****
10          *  ****
11          *  ***
12          *  **
13          *  *
14          */
15         for (int i = 0; i < 5; i++) {
16             for (int j = 0; j < 5 - i; j++) {
17                 System.out.print("*");
18             }
19             System.out.println();
20         }
21 
22     }
23 }
 1 package cn.itcast.day04_for;
 2 
 3 public class test3 {
 4 
 5     public static void main(String[] args) {
 6 
 7         /*
 8          * 案例三:
 9          *  *
10          *  **
11          *  ***
12          *  ****
13          *  *****
14          *
15          */
16 
17         for (int i = 0; i < 5; i++) {
18             for (int j = 0; j <= i; j++) {
19                 System.out.print("*");
20             }
21             System.out.println();
22         }
23 
24     }
25 }
 1 package cn.itcast.day04_for;
 2 
 3 public class test4 {
 4 
 5     public static void main(String[] args) {
 6 
 7         /*
 8          * 案例四:
 9          *  54321
10          *  5432
11          *  543
12          *  54
13          *  5
14          *
15          */
16 
17         for (int i = 0; i < 5; i++) {
18             for (int j=5;j>i;j--){
19                 System.out.print(j);
20             }
21             System.out.println();
22         }
23 
24     }
25 }
 1 package cn.itcast.day04_for;
 2 
 3 public class test5 {
 4 
 5     public static void main(String[] args) {
 6 
 7         /*
 8          * 案例五:
 9          * 1
10          * 12
11          * 123
12          * 1234
13          * 12345
14          */
15 
16         for (int i = 0; i < 5; i++) {
17             for (int j = 0; j <= i; j++) {
18                 System.out.print(j+1 );
19             }
20             System.out.println();
21         }
22 
23     }
24 
25 }
 1 package cn.itcast.day04_for;
 2 
 3 public class test6 {
 4     public static void main(String[] args) {
 5 
 6         /*
 7          * 案例六:
 8          *  打印九九乘法表
 9          *
10          */
11 
12         for (int i = 1; i <= 9; i++) {
13             for (int j = 1; j <= i; j++) {
14                 System.out.print(i + "*" + j + "=" + i * j + "\t");
15             }
16             System.out.println();
17         }
18     }
19 }
 1 package cn.itcast.day04_for;
 2 
 3 public class test7 {
 4 
 5     public static void main(String[] args) {
 6 
 7         /*
 8          * 案例七:
 9          *  * * * * *
10          *   * * * *
11          *    * * *
12          *     * *
13          *      *
14          */
15 
16         for (int i = 0; i < 5; i++) {
17             for (int j=0;j<i;j++){
18                 System.out.print(" ");
19             }
20             for (int j=0;j<5-i;j++){
21                 System.out.print("* ");
22             }
23             System.out.println();
24         }
25     }
26 }

猜你喜欢

转载自www.cnblogs.com/xuan-lin/p/11230919.html