返回列表 發帖

巢狀迴圈 - 小星星

本帖最後由 tonyh 於 2014-6-7 14:37 編輯

利用巢狀迴圈, 將符號*整齊排列如下:

*
**
***
****
*****
  1. public class ch21
  2. {
  3.     public static void main(String args[])
  4.     {
  5.           for(int i=1; i<=5; i++)
  6.           {
  7.                for(int j=1; j<=i; j++)
  8.                {
  9.                     System.out.print("*");
  10.                }
  11.                System.out.println();
  12.           }
  13.     }
  14. }
複製代碼

  1. public class ch22
  2. {
  3.     public class void main(String args[])
  4.     {
  5.         for(int i=1;i<=5;i++)
  6.         {
  7.             for(int j=1;j<=i;j++)
  8.             {
  9.                 System.out.print("*");
  10.             }
  11.             System.out.println();
  12.         }
  13.     }

  14. }
複製代碼

TOP

  1. public class ch21
  2. {
  3.     public static void main(String args[])
  4.     {
  5.           for(int i=1; i<=5; i++)
  6.           {
  7.                for(int j=1; j<=i; j++)
  8.                {
  9.                     System.out.print("*");
  10.                }
  11.                          System.out.println();
  12.           }
  13.     }
  14. }
複製代碼

TOP

  1. public class ch21
  2. {
  3.     public static void main(String args[])
  4.     {
  5.           for(int i=1; i<=5; i++)
  6.           {
  7.                for(int j=1; j<=i; j++)
  8.                {
  9.                     System.out.print("*");
  10.                }
  11.                System.out.println();
  12.           }
  13.     }
  14. }
複製代碼

TOP

  1. public class ch21
  2. {
  3.     public static void main(String args[])
  4.     {
  5.           for(int i=1; i<=5; i++)
  6.           {
  7.                for(int j=1; j<=i; j++)
  8.                {
  9.                     System.out.print("*");
  10.                }
  11.                System.out.println();
  12.           }
  13.     }
  14. }
複製代碼

TOP

  1. public class ch21
  2. {
  3.     public static void main(String args[])
  4.     {
  5.           for(int i=1; i<=5; i++)
  6.           {
  7.                for(int j=1; j<=i; j++)
  8.                {
  9.                     System.out.print("*");
  10.                }
  11.                System.out.println();
  12.           }
  13.     }
  14. }
複製代碼

TOP

返回列表