Board logo

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

作者: tonyh    時間: 2014-6-7 14:22     標題: 巢狀迴圈 - 小星星 (二)

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

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

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

作者: 張瀚仁    時間: 2014-6-7 14:42

  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=6-i;j>=1;j--)
  8.             {
  9.                 System.out.print("*");
  10.             }
  11.             System.out.println();
  12.         }
  13.     }

  14. }
複製代碼

作者: 鎧言    時間: 2014-6-7 14:44

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

作者: 黃崇維    時間: 2014-6-7 14:44

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

  14. }
複製代碼

作者: 劉泳鱔    時間: 2014-6-7 14:45

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

作者: 林以諾    時間: 2014-6-7 14:46

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





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