读取用户键盘输入的方法

阅读 83

2023-01-17


最简单的:

BufferedReader br = 

new BufferedReader(

new InputStreamReader(System.in));

String s=in.readLine();

      //从输入流in中读入一行,并将读取的值赋值给字符串变量s

      System.out.println("Input value is: "+s);

      int i = Integer.parseInt(s);//转换成int型


JDK1.5 中新提供的:
 

Scanner sc = new Scanner(System.in);

int i = sc.nextInt();


精彩评论(0)

0 0 举报