Java从键盘获取输入的方法

来源:互联网 发布:excel编程vba 编辑:程序博客网 时间:2024/05/29 04:03

方法1:

InputStreamReader is = new BufferedReader(new InputStreamReader(System.in));
用法:获取输入的字符串,可以转换成int,double


方法2:

Scanner sc = new Scanner(System.in);String name = sc.nextLine();   int age = sc.nextInt();float salary = sc.nextFloat();
用法:Scanner 有很多方法可以调用,可以控制输入类型

原创粉丝点击