• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

input reading problem

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic