在java中,如何从键盘输入到字符串中
来源:百度知道 编辑:UC知道 时间:2024/09/13 02:17:37
import java.util.Scanner;
public class InputString {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String str = null;
System.out.println("请输入您想输入的字符串:");
str = s.next();
System.out.println("您输入的是:");
System.out.println(str);
}
}
BufferedReader类 ------JDK1.4
==========================================
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BoffReader {
public static void main(String[] args) {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
String s=in.readLine();
System.out.println(s);
} catch (IOException e) {
e.printStackTrace();
}
}
}
==========================================
Scanner类 ----JDK1.5以上
impo