读取用户键盘输入的方法

来源:互联网 发布:vb combo1.listindex 编辑:程序博客网 时间:2024/04/30 05:27
最简单的:
 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();
原创粉丝点击