返回列表 發帖

資料輸入 (一)

本帖最後由 陳品肇 於 2019-5-25 16:08 編輯

運用套件java.util 下的 Scanner類別, 作字串輸入的練習.
  1. import java.util.Scanner;

  2. public class D0525 {

  3.         public static void main(String[] args) {
  4.                 // TODO 自動產生的方法 Stub
  5.                 Scanner c = new Scanner(System.in);
  6.                 String str1,str2;
  7.             System.out.print("輸入字串一: ");
  8.             str1=c.nextLine();
  9.             System.out.println("字串一: "+str1);
  10.             System.out.print("輸入字串二: ");
  11.             str2=c.nextLine();
  12.             System.out.println("字串二: "+str2);
  13.                
  14.         }

  15. }
複製代碼

返回列表