- import java.io.Console;
- public class ch19
- {
- public static void main(String args[])
- {
- Console c=System.console();
- int x,y;
- System.out.print("輸入初始值:");
- x=Integer.parseInt(c.readLine());
- System.out.print("輸入結束值:");
- y=Integer.parseInt(c.readLine());
- if(y>x)
- {
- for(int i=x;i<=y;i++)
- {
- System.out.print(i+" ");
- }
- }
- else if(x>y)
- System.out.println("輸入錯誤");
- else
- System.out.println("輸入錯誤");
- }
- }
複製代碼 |