Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

input reading problem

 
Jason sigel
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

D:\mycode>javac my1.java
my1.java:10: Method readDouble() not found in class java.io.BufferedReader.
double d=br.readDouble();
^
1 error

I am getting this error .I have again write out a simple program in this form.

Now tell me why i can not use br.readDouble()
jaideep
[I added UBB CODE tags to your source code to make it more readable. Please try to use
them in the future. Learn more about UBB codes here - Ajith ]

[This message has been edited by Ajith Kallambella (edited September 27, 2000).]
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the error message?

D:\mycode>javac my1.java
my1.java:10: Method readDouble() not found in class java.io.BufferedReader. double d=br.readDouble();

That's why.
BufferedReader only gives you the advantage of buffering your reads from the stream. It does a 'read-ahead' from the stream so when you read, you are actually reading from the buffer which is faster than reading from the stream itself. Eventhough it wraps an input stream, it doesnot deal with any of the methods associated with the underlying inputstream object. So, if you have to use BufferedReader, you should live with the high-level methods it provides for reading. Ofcourse, you can always use other ways to convert the String that was read.
Hope that helps,
Ajith
 
Marie
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Readers and Writers only work with Unicode... don't they?
to read primitives, you need to use RandomAccessFile or one of the InputStreams
i think....
 
Jason sigel
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tHANKS AJITH,
I got where I had made mistake.Yes UBB code make effective way to present code.
Marie you are right.This is what I am doing here.I am taking input stream and passing it to buffered reader.
InputStream converts bytes to char and buffered reader is character reader.
jaideep
 
Jason sigel
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more question related elementry thing here.
why I have to initialize d=0.00 here in the code .

WHY NOT JUST double d=Double.parseDouble(br.readLine());}
jaideep

[This message has been edited by Ajith Kallambella (edited September 27, 2000).]
 
Henry H
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

WHY NOT JUST double d=Double.parseDouble(br.readLine());}
jaideep[/b]
</BLOCKQUOTE>
That would actually fail to compile since you're declaring 'd' twice in the method. Marked 1) and 2) in the code.
Change 1) to: double d = 0.0;" and
2) to d=Double.parseDouble(br.readLine());
You need to initialize d before you go into any code block(ie try/catch, loops)

[This message has been edited by Henry H (edited September 27, 2000).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic