How do I read char,int,double, string from a keyboad ( Terminal ).
Posted on 1998-07-22
How do I read Integer, Double, Char and String data type cleanly from the Keyboard Terminal. I have a program which requires user input and I dont want to use Applet for testing. I can do this in a crude way but I want a clean way to handle this.
What I have done to handle this is to read each line and then parse it using StringTokenizer to read doubles. But readLine in DataInputStream is also a depreciated. So I really dont want to use this. Is there a clean method to do this??
Also How do I handle if I have two double on one line seperated by space or two double on two seperate lines??
I have a following sample program but it does not work.
public class IOTest
public static void main(String args)
DataInputStream dis = new DataInputStream ( System.in );
double d = dis.readDouble() ;
System.out.println ( "Double d = " +d1 ) ;
} catch ( IOException io )
System.out.println ( "readDouble Exception: "+io.toString() ) ;