使用 Scanner s = new Scanner(System.in) 或 BufferedReader br = new BufferedReader(new InputStreamReader(System.in))都可以实现键盘的输入,这两个有什么区别啊,用哪个好些?- import java.io.*;
- import java.util.Scanner;
- public class JianPanShuRu {
- public static void main(String[] args) throws IOException {
- System.out.print("请输入文字,回车键结束:");
- Scanner s = new Scanner(System.in);
- String str = s.next();
- System.out.println("请输入的str:"+str);
- System.out.println();
-
-
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
-
- System.out.print("请输入一系列文字、:");
- String text =br.readLine();
- System.out.println("请输入text:"+text);
- }
-
- }
复制代码
|
|