• 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

Prob with BufferedReader(System.in)

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


After the Formula is done and I type d I get a weird error that Stops the prgm. HELP ME FIX IT
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No idea
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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');
}
}
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic