File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Prob with BufferedReader( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Prob with BufferedReader(" Watch "Prob with BufferedReader(" New topic

Prob with BufferedReader(

George Han

Joined: Aug 17, 2005
Posts: 17

After the Formula is done and I type d I get a weird error that Stops the prgm. HELP ME FIX IT
mathew john

Joined: Dec 14, 2004
Posts: 19
what is the Error You are getting .if You are getting a Number Format Exception .That is because the application has attempted to convert a character or a string to one of the numeric types, but that the string does not have the appropriate format.So you cannot enter a String or Character .

if You are getting this Error Value out of range You better check out the ParseByte .You can check the ParseFloat and ParseDouble to accomadate higher range .
George Han

Joined: Aug 17, 2005
Posts: 17
The error I get is Exception in thread "main" java.langNumberFormatException: empty String

at java.lang.FloatingDecimal.readJavaFormatString<>
at java.lang.Float.parseFloat<>
at Fahrenheit.main<>
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 691
Break the following line into separate statements and test/display results.
Ie read the data, test data present, echo the input(for testing) and then convert it.

Or use: try{}catch() block to catch Exceptions

In your code: Which line is line 14? The one with the error?
George Han

Joined: Aug 17, 2005
Posts: 17
No idea
James Hejmanowski

Joined: Aug 22, 2005
Posts: 8
From one greenhorn to another...

Sorry about the fonts... I don't know how to quote code in the body of the message yet... In any event the system hangs on reaching lines 17 and 18 in your original code below (commented below); these lines appear to be un-necessary. Commenting these lines out yields runnable code; though input values are limited to a range of -128 to 127 (Byte value range).

One thought... Why re-declare br with every iteration of your loop? the code runs with "BufferedReader br = new BufferedReader(new InputStreamReader(;" placed before the loop.


import java.lang.Character;
import java.applet.Applet;
import java.lang.String;
class Fahrenheit {
public static void main(String args[]) throws Exception {
float realFahrenheit;
float Celsius;
char Answer;
int Yay;
BufferedReader br = new BufferedReader(new InputStreamReader(;
System.out.print("Enter F: ");
realFahrenheit = Byte.parseByte(br.readLine().trim());
Celsius = (realFahrenheit - 32) * 5 / 9;
System.out.println(realFahrenheit+" F is "+Celsius+" C");
Answer = (char); //Appears un-needed.; //Appears un-needed.
Answer = Character.toUpperCase(Answer);
}while(Answer != 'Q');

"I drank what"?<br /> -Socrates
Consider Paul's rocket mass heater.
subject: Prob with BufferedReader(
It's not a secret anymore!