Board logo

標題: 巢狀迴圈 - 小星星 [打印本頁]

作者: tonyh    時間: 2012-9-1 17:00     標題: 巢狀迴圈 - 小星星

本帖最後由 tonyh 於 2012-9-1 17:04 編輯

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

*
**
***
****
*****
  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. }
複製代碼

作者: t2364705    時間: 2012-9-1 17:05

  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. }
複製代碼

作者: 粘靖瑜    時間: 2012-9-1 17:08

  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. }
複製代碼

作者: 劉漢文    時間: 2012-9-1 17:12

  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. }
複製代碼

作者: 蔡昀佑    時間: 2012-9-1 17:15

  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. }
複製代碼

作者: 尤泓鈞    時間: 2012-9-8 11:14

  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. }
複製代碼

作者: 黃博鴻    時間: 2012-10-13 15:33

  1. public class ch19
  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.        }System.out.println();
  11.     }
  12.      
  13.   }
  14. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2