import java.io.*; /** The Console class consists of static methods that allow easy reading of the basic data types double, int, and String from standard input. It must be placed in the same directory containing the source code using it.

Usage Example:

     System.out.println("Enter a double number: ");
     double x = Console.readDouble();
      System.out.println("You have entered: " + x);
      
@author Bert G. Wachsmuth @version 98/03/10 */ public class Console { /** Reads a single double value from the keyboard. If there is an error, the program will halt. @return double */ public static double readDouble() { String tmpX = readString().trim(); try { return (new Double(tmpX)).doubleValue(); } catch (NumberFormatException ne) { System.err.println("Not a double. Quitting ..."); System.exit(-1); return 0.0; } } /** Reads a single int value from the keyboard. If there is an error, the program will halt. @return int */ public static int readInt() { String tmpX = readString().trim(); try { return Integer.parseInt(tmpX); } catch (NumberFormatException ne) { System.err.println("Not an integer. Quitting ..."); System.exit(-1); return -1; } } /** Reads a String from the keyboard until RETURN or ENTER key is pressed. @return String */ public static String readString() { String string = new String(); try { int cc = System.in.read(); while (!((cc == 13) || (cc == 10))) { string += (char) cc; cc = System.in.read(); } } catch (IOException e) { } return string; } }