This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes BufferedReader problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "BufferedReader problem" Watch "BufferedReader problem" New topic
Author

BufferedReader problem

Nathan Doe
Greenhorn

Joined: Oct 17, 2009
Posts: 24
I am trying to prompt the user to enter two numbers and then have those numbers set to the two variables cNum and sNum.



The problem is that when I run this when i enter a value the output is a number in the 50's.
Any help is appreciated.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
You need to see what the read() method does, and work out why you get 51 when you expect 3. There are other methods in those classes, eg readLine() which are probably more suitable. There is no need to use two BufferedReaders in the same method to read from the same source. Make sure you use a finally block to close the Reader, otherwise you may end up with "resource leaks."

You may find it much easier if you use the Scanner class.
Nathan Doe
Greenhorn

Joined: Oct 17, 2009
Posts: 24
Thanks!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
I presume you have got it worked out then . . . well done
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BufferedReader problem
 
Similar Threads
how to add number of digit in array
Digits in Array
how to add number of digit in array
trouble with operator
Threads