数据结构(Java语言版) 用到的ConsoleReader.java
数据结构(Java语言版) 用到的ConsoleReader.java
一个方便的键盘输入程序,可以在其他程序中import
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
/**
*
* @author HP
*
* 一个方便的键盘输入程序,可以在其他程序中import
*
*/
public class ConsoleReader
{
private BufferedReader reader;
public ConsoleReader(InputStream inStream) {
reader = new BufferedReader(new InputStreamReader(inStream));
}
public int readInt() {
String inputString = readLine();
int n = Integer.parseInt(inputString);
return n;
}
public double readDouble() {
String inputString = readLine();
double x = Double.parseDouble(inputString);
return x;
}
public String readLine() {
String inputLine = "";
try {
inputLine = reader.readLine();
} catch (IOException e) {
System.out.println(e);
System.exit(1);
}
return inputLine;
}
public static void main(String s[]) {
int i;
System.out.println("Please input a integer :");
ConsoleReader reader = new ConsoleReader(System.in);
i = reader.readInt();
System.out.println(i);
}
}