// Simple methods for reading from standard system input. // // A method is provided for each of the data types: // int, float, double, char and String // The methods assume that each input value is terminated by a newline. import java.io.*; import java.text.*; public class Stdin { // Read a String from standard system input public static String getString() { InputStreamReader converter = new InputStreamReader (System.in); BufferedReader in = new BufferedReader (converter); try { return in.readLine(); } catch (Exception e) { return ""; } } // Read a Number as a String from standard system input // Return the Number public static Number getNumber() { String numberString = getString(); try { numberString = numberString.trim().toUpperCase(); return NumberFormat.getInstance().parse( numberString ); } catch (Exception e) { // if any exception occurs, just give a 0 back return new Integer( 0 ); } } // Read an integer from standard system input public static int getInt() { return getNumber().intValue(); } // Read a float from standard system input public static float getFloat() { return getNumber().floatValue(); } // Read a double from standard system input public static double getDouble() { return getNumber().doubleValue(); } // Read a char from standard system input public static char getChar() { String s = getString(); if (s.length () >= 1) return s.charAt (0); else return '\n'; } }