[5440] in java-interest

home help back first fref pref prev next nref lref last post

Confusion with DataInputStream ...

daemon@ATHENA.MIT.EDU (Dhaval M Shah)
Thu Feb 8 22:58:51 1996

From: Dhaval M Shah <dhaval@cs.uow.edu.au>
To: java-interest@java.sun.com
Date: Thu, 8 Feb 1996 22:09:59 +1100 (EST)
Cc: owner-java-interest@java.sun.com

Hello Everybody,

I am a student with good 'C' background and trying to learn
java.

I want to read in integer, double and float values - 
but did not find a suitable manner to do that in java !!!!

I tried DataInputStream and am particularly confused with the 
behaviour of DataInputStream.

This is the following code fragment I tried :
----------
import java.io.*;

class mainclass
{
 public static void main(String args[])
	throws java.io.IOException
 {
  int i;
  DataInputStream inputstream = new DataInputStream(System.in);
			// Associate it to System.in

  System.out.println("Enter i : ");
  i = inputstream.readInt();
  
  System.out.println(i);
 }
}
---------
In C, we can give scanf("%3d",...) statements to read in an
integer of 3 digits etc.

When I run the above java code fragment, I have to type in
atleast 3 digits, to come out of the inputstream.readInt()
line and the System.out.println(i) prints "junk".

Is there a way to read in integers, double and float from
the Standard Input apart from reading in strings and converting it to int,
double or float

Hope to hear soon...

Thanks in advance ....

Dhaval

-- 
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
   Dhaval M. Shah                                                        
   dhaval@cs.uow.edu.au                 (Home) : +61 42 258519
   Dept. of Computer Science		
   University of Wollongong		2/13 Catherine St., Gwynneville, 
   NSW 2522	Australia    		NSW 2500     Australia
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post