Skip to content

Instantly share code, notes, and snippets.

@guizmaii
Last active August 29, 2015 13:57
Show Gist options
  • Save guizmaii/9773603 to your computer and use it in GitHub Desktop.
Save guizmaii/9773603 to your computer and use it in GitHub Desktop.
import java.io.*;
public class Terminal {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
public static String readString() {
String tmp = "";
try {
tmp = in.readLine();
} catch (IOException e) {
exceptionHandler(e);
}
return tmp;
}
public static int readInt() {
int x = 0;
try {
x = Integer.parseInt(readString());
} catch (NumberFormatException e) {
exceptionHandler(e);
}
return x;
}
public static boolean readBoolean() {
boolean b = true;
try {
b = Boolean.valueOf(readString()).booleanValue();
} catch (NumberFormatException e) {
exceptionHandler(e);
}
return b;
}
public static double readDouble() {
double x = 0.0;
try {
x = Double.valueOf(readString()).doubleValue();
} catch (NumberFormatException e) {
exceptionHandler(e);
}
return x;
}
public static char readChar() {
String tmp = readString();
if (tmp.length() == 0)
return '\n';
else {
return tmp.charAt(0);
}
}
protected static void exceptionHandler(Exception ex) {
TerminalException err = new TerminalException(ex);
throw err;
}
}
class TerminalException extends RuntimeException {
Exception ex;
TerminalException(Exception e) {
ex = e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment