consoleinput.java
来自「21天学通JAVA2(第三版)(专业参考版)」· Java 代码 · 共 31 行
JAVA
31 行
import java.io.*;
public class ConsoleInput {
public static String readLine() {
StringBuffer response = new StringBuffer();
try {
BufferedInputStream buff = new
BufferedInputStream(System.in);
int in = 0;
char inChar;
do {
in = buff.read();
inChar = (char) in;
if (in != -1) {
response.append(inChar);
}
} while ((in != -1) & (inChar != '\n'));
buff.close();
return response.toString();
} catch (IOException e) {
System.out.println("Exception: " + e.getMessage());
return null;
}
}
public static void main(String[] arguments) {
System.out.print("\nWhat is your name? ");
String input = ConsoleInput.readLine();
System.out.println("\nHello, " + input);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?