返回列表 發帖

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

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

返回列表