2006-07-21 04:19:41Yang’s

[Java]取得使用者輸入


import java.util.Scanner;

public class UserInput {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print(”Please input your name: ”);
System.out.printf(”Hello! %s!”, scanner.next());
}
}


讀一整行的方法:

import java.io.*;

public class GetInput {
public static void main(String[] args) throws IOException {
BufferedReader buf = new BufferedReader(
new InputStreamReader(System.in));

System.out.print(”請輸入一列文字: ”);
String text = buf.readLine();
System.out.println(”您輸入的文字: ” + text);
}
}