- import java.io.Console; //引入java.io類別
- public class ch05 //類別
- {
- public static void main(String args[]) //方法
- {
- Console console = System.console();
- int x;
- System.out.print("請輸入一個整數:");
- x = Integer.parseInt(console.readLine());
- //Integer.parseInt(String s)只是將是數字的字串轉成數字
- //參考http://ubuntu-rubyonrails.blogspot.tw/2009/01/java-integervalueof-integerparseint.html
- System.out.print("輸入的整數為:"+x);
- //若需入非數字時,需要有錯誤訊息來接(Exception throw),尚未教到
- }
- }
複製代碼 |