aspose file tools*
The moose likes Beginning Java and the fly likes Prob with BufferedReader(System.in) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Prob with BufferedReader(System.in)" Watch "Prob with BufferedReader(System.in)" New topic
Author

Prob with BufferedReader(System.in)

George Han
Greenhorn

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
Greenhorn

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
Greenhorn

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

at java.lang.FloatingDecimal.readJavaFormatString<FloatingDecimal.java:983>
at java.lang.Float.parseFloat<float.java:222>
at Fahrenheit.main<Fahrenheit.java:14>
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
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
Greenhorn

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

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(System.in));" placed before the loop.


code:

import java.io.*;
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;
do{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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)System.in.read(); //Appears un-needed.
System.in.read(); //Appears un-needed.
Answer = Character.toUpperCase(Answer);
}while(Answer != 'Q');
}
}


"I drank what"?<br /> -Socrates
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prob with BufferedReader(System.in)