/* * This example shows how to use BufferedReader. In Culwin's textbook * and in our lecture, we have used DataInputStream for our readLine() * method. That is * DataInputStream in = new DataInputStream(System.in) * This method has been deprecated in the newer versions of Java. * In newer version of Java, the readLine() method comes from * BufferedReader. This is an example of how to use it. * The BufferedReader is available in JDK 1.1. Our current J++ does * not support this. * * This version uses try/catch clause. * * Xiannong Meng * apr-4-1998 */ import java.io.*; // the new readLine is in java.io.BufferedReader public class BufIoV2 { public static void main(String argv[]) { int n = 0; double r = 0; Double R = new Double(0.0); String str = ""; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("type an integer : "); str = in.readLine(); n = Integer.parseInt(str); System.out.println(" integer value is " + n); } catch (IOException e) {}; // no local action is taken, propagate upwards try { System.out.print("type a double : "); str = in.readLine(); R = Double.valueOf(str); r = R.doubleValue(); System.out.println(" double value is " + r); } catch (IOException e) {}; // no local action is taken, propagate upwards } // End main }