Java 中,如何获取键盘输入呢?
看下面代码:
- /**
- *
- * @return
- * @throws IOException
- */
- public static String getStringKeyboard() throws IOException {
- InputStreamReader isr = new InputStreamReader(System.in);
- BufferedReader br = new BufferedReader(isr);
- String s = br.readLine();
- return s;
- }
- public static int getIntKeyboard() {
- Scanner sca = new Scanner(System.in);
- return sca.nextInt();
- }
测试: