返回列表 發帖
  1. import java.io.Console;
  2. public class ch19
  3. {
  4.     public static void main(String args[])
  5.     {
  6.         Console c=System.console();
  7.         int x,y;
  8.         System.out.print("輸入初始值:");
  9.         x=Integer.parseInt(c.readLine());
  10.         System.out.print("輸入結束值:");
  11.         y=Integer.parseInt(c.readLine());
  12.         if(y>x)
  13.         {
  14.             for(int i=x;i<=y;i++)
  15.             {
  16.                 System.out.print(i+" ");
  17.             }
  18.         }
  19.         else if(x>y)
  20.             System.out.println("輸入錯誤");
  21.         else
  22.             System.out.println("輸入錯誤");

  23.     }
  24. }
複製代碼

TOP

返回列表