469,330 Members | 1,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

Convert temperatures in fahrenheit to celsius

Ok i need to create a java program that repeatedly read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered.

My program is:
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. // Converter.java
  3. public class Converter
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         Scanner sc = new Scanner(System.in);
  8.         System.out.print("Enter temp: ");
  9.         int temp = sc.nextInt();
  10.         System.out.println(convertToC(temp));
  11.     }
  12.          public static int convertToC(int temp)
  13.     {
  14.         return ((temp - 32 ) * 5/9);
  15.     }
  16. }                
  17.  
I would really appreaciate it. Thank you. <email removed>
Nov 14 '08 #1
11 22879
JosAH
11,448 Expert 8TB
What is your question?

kind regards,

Jos

ps. use those [ code ] tags for readability reasons next time when you post code.
Nov 14 '08 #2
What is your question?

kind regards,

Jos

ps. use those [ code ] tags for readability reasons next time when you post code.

umm. my question is using the program that I have already posted, can you please modify that program so that it could read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered. Thank you very much for replying. Sorry about the code tags.
Nov 14 '08 #3
JosAH
11,448 Expert 8TB
umm. my question is using the program that I have already posted, can you please modify that program so that it could read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered. Thank you very much for replying. Sorry about the code tags.
And what does your program do? Note that integer division does not do what
people expect it to do.

kind regards,

Jos
Nov 14 '08 #4
ohh sorry, right now after a user inputs a number, the program outputs it in degrees Celcius.
Nov 14 '08 #5
JosAH
11,448 Expert 8TB
ohh sorry, right now after a user inputs a number, the program outputs it in degrees Celcius.
Craft a liitle loop then and a small method that asks the user to enter a number
in Fahrenheit degrees:

Expand|Select|Wrap|Line Numbers
  1. for (int f= getFahrenheit(); f <= 212; f= getFahrenheit())
  2.    System.out.println(f+"F = "+convertToC(f)+"C");
  3.  
The convertToC() method converts Fahrenheit (its parameter) to Celcius.
You already have that method.

kind regards,

Jos
Nov 14 '08 #6
yeah I know ,but ok. Maybe it would be easier for you to understand my question if it is wrote out like this:



"Modify your main function in the Converter class to repeatedly read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered."

Sorry about the confusion
Nov 14 '08 #7
JosAH
11,448 Expert 8TB
yeah I know ,but ok. Maybe it would be easier for you to understand my question if it is wrote out like this:



"Modify your main function in the Converter class to repeatedly read temperatures in Fahrenheit and convert them to Celsius until a temperature > 212 F (the boiling point of water) is entered."

Sorry about the confusion
But I just told you how to do that ...

kind regards,

Jos
Nov 14 '08 #8
oh, now I see it sorry about that. Not to sound stupid but, where would I insert that part you gave me at.
Nov 14 '08 #9
wow thanks alot for the help. I really needed it. Thanks again
Nov 14 '08 #10
But I just told you how to do that ...

kind regards,

Jos
Once again I am sorry, but I am a begginner in Java programming. I tried to do what you told me but I have one error. Line 17 has the error message that reads [PHP]1 error

----jGRASP wedge2: exit code for process is 1.[/PHP]

[PHP]import java.util.*;
// Converter.java
public class Converter
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter temp: ");
int temp = sc.nextInt();
System.out.println(convertToC(temp));
}
public static int convertToC(int temp)
{
return ((temp - 32 ) * 5/9);
}
{
for (int f= getFahrenheit()); f <= 212;
f= getFahrenheit())
System.out.println(f+"F = "+convertToC(f)+"C");
for (int f= getFahrenheit();
f <= 212; f= getFahrenheit())
System.out.println(f+"F = "+convertToC(f)+"C");
}
}[/PHP]
Nov 15 '08 #11
JosAH
11,448 Expert 8TB
Basically your program structure looks like this now:

Expand|Select|Wrap|Line Numbers
  1. public class Converter {
  2.     public static void main(String[] args) { ... }
  3.      public static int convertToC(int temp) { ... }
  4.      { /* some garbage statements ... */ }
  5. }
  6.  
That doesn't make sense does it? I had expected that loop I wrote for you
somewhere in the main method; not dangling at the end of the class, not in
any method at all. On top of that that bunch of statements contain quite a
lot of garbage as well.

kind regards,

Jos
Nov 15 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

19 posts views Thread by Lauren Quantrell | last post: by
1 post views Thread by Logan X via .NET 247 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.