Board logo

標題: for 迴圈 (三) [打印本頁]

作者: tonyh    時間: 2012-8-25 16:29     標題: for 迴圈 (三)

本帖最後由 tonyh 於 2012-8-25 16:34 編輯

顯示100內所有奇數, 從99開始倒數至1.
  1. public class ch16
  2. {
  3.      public static void main(String args[])
  4.      {
  5.            for(int i=99; i>=1; i=i-2)  //i=i-2 或 i-=2
  6.            {
  7.                 System.out.println(i);
  8.            }
  9.      }
  10. }
複製代碼

作者: t3742238    時間: 2012-8-25 16:34

  1. import java.io.Console;
  2. public class ch13
  3. {
  4.    public static void main(String args[])
  5.    {
  6.        for(int i=99; i>=1; i=i-2)
  7.        {
  8.          System.out.println(i);
  9.        }
  10.    }
  11. }
複製代碼

作者: t2364705    時間: 2012-8-25 16:34

  1. public class ch16
  2. {
  3.     public static void main(String srgs[])
  4.     {
  5.         for(int i=99; i>=1; i-=2)
  6.         {
  7.             System.out.println(i);
  8.         }
  9.     }
  10. }
複製代碼

作者: 尤泓鈞    時間: 2012-8-25 16:34

  1. public class ch16
  2. {
  3.     public static void main(String srgs[])
  4.     {
  5.         for(int i=99; i>=1; i=i-2)
  6.         {
  7.             System.out.println(i);
  8.         }
  9.     }
  10. }
複製代碼

作者: 粘靖瑜    時間: 2012-8-25 16:38

  1. public class ch16
  2. {
  3.     public static void main(String args[])
  4.     {
  5.           for(int i=99; i>=1; i=i-2)
  6.           {
  7.                System.out.println(i);
  8.           }

  9.     }

  10. }
複製代碼

作者: 蔡昀佑    時間: 2012-8-25 16:40

  1. public class ch16
  2. {
  3.      public static void main(String args[])
  4.      {
  5.            for(int i=99; i>=1; i=i-2)
  6.            {
  7.                 System.out.println(i);
  8.            }
  9.      }
  10. }
複製代碼

作者: 劉漢文    時間: 2012-8-25 16:42

  1. public class ch15
  2. {
  3.     public static void main(String srgs[])
  4.     {
  5.         for(int i=2; i<=100; i+=2)
  6.         {
  7.             System.out.println(i);
  8.         }
  9.     }
  10. }
複製代碼

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

  1. {
  2.   public static void main(String args[])
  3.   {
  4.     for(int i=99; i>=1; i-=2)
  5.     {
  6.     System.out.println(i);
  7.     }
  8.   }
  9. }
複製代碼





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