返回列表 發帖
  1. import java.io.Console; //引入java.io類別
  2. public class ch05 //類別
  3. {
  4. public static void main(String args[]) //方法
  5. {
  6.    Console console = System.console();
  7.    int x;
  8.    System.out.print("請輸入一個整數:");
  9.    x = Integer.parseInt(console.readLine());
  10.    //Integer.parseInt(String s)只是將是數字的字串轉成數字
  11.    //參考http://ubuntu-rubyonrails.blogspot.tw/2009/01/java-integervalueof-integerparseint.html
  12.    System.out.print("輸入的整數為:"+x);
  13.    //若需入非數字時,需要有錯誤訊息來接(Exception throw),尚未教到
  14. }

  15. }
複製代碼

TOP

返回列表