public class StandardInputReader {
private static BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in));
/**
* Read a boolean value from standard input stream.
*
* @return a boolean value.
* @throws IOException
*/
public static boolean readBoolean() throws IOException {
String strBoolean = reader.readLine();
// return Boolean.valueOf(strBoolean).booleanValue();
if (strBoolean.equalsIgnoreCase("true")) {
return true;
} else if (strBoolean.equalsIgnoreCase("false")) {
return false;
} else {
throw new NumberFormatException("For input string: \""
+ strBoolean +"\"");
}
}
/**
* Read a byte value from standard input stream.
*
* @return a byte value.
* @throws IOException
*/
public static byte readByte() throws IOException {
return Byte.parseByte(reader.readLine());
}
/**
* Read a short value from standard input stream.
*
* @return a short value.
* @throws IOException
*/
public static short readShort() throws IOException {
return Short.parseShort(reader.readLine());
}
/**
* Read a int value from standard input stream.
*
* @return a int value.
* @throws IOException
*/
public static int readInt() throws IOException {
return Integer.parseInt(reader.readLine());
}
/**
* Read a long value from standard input stream.
*
* @return a long value.
* @throws IOException
*/
public static long readLong() throws IOException {
return Long.parseLong(reader.readLine());
}
/**
* Read a float value from standard input stream.
*
* @return a float value.
* @throws IOException
*/
public static float readFloat() throws IOException {
return Float.parseFloat(reader.readLine());
}
/**
* Read a double value from standard input stream.
*
* @return a double value.
* @throws IOException
*/
public static double readDouble() throws IOException {
return Double.parseDouble(reader.readLine());
}
/**
* Read a line of text. A line is considered to be terminated by any one
* of a line feed ('\n'), a carriage return ('\r'), or a carriage return
* followed immediately by a linefeed.
*
* @return A String containing the contents of the line, not including
* any line-termination characters, or null if the end of the
* stream has been reached
*
* @exception IOException If an I/O error occurs
*/
public static String readLine() throws IOException {
return reader.readLine();
}