返回列表 發帖

資料輸入 (一)

本帖最後由 tonyh 於 2016-3-11 21:10 編輯

運用套件 java.io 下的 Console 類別, 作字串輸入的練習.

  1. import java.io.Console;   //引入套件java.io下的Console類別
  2. public class Ch05
  3. {
  4.     public static void main(String args[])
  5.     {
  6.          String str1,str2;
  7.          Console c=System.console();  //在Console類別下建立一名為c的實體物件,使用到System類別的console()方法
  8.          System.out.print("請輸入字串一: ");
  9.          str1=c.readLine();      //使用readLine()方法來抓取自鍵盤輸入的字串
  10.          System.out.println("字串一: "+str1);
  11.          System.out.print("請輸入字串二: ");
  12.          str2=c.readLine();
  13.          System.out.println("字串二: "+str2);
  14.     }
  15. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

返回列表