English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Can anyone help me?, this is my code:

//identifier declarations


final int BOILING_IN_F = 212; // freezing temperature
int fToC;


// Convert Fahrenheit temperatures to Celsius

fToC = 5/9 * (BOILING_IN_F - 32);
output = BOILING_IN_F + " in Fahrenheit is " + fToC+ " in Celsius.";
System.out.println(output);
System.out.println();

2006-09-14 18:31:05 · 6 answers · asked by lanxxelot 1 in Computers & Internet Programming & Design

6 answers

variable type int is whole numbers only, no fractions. You need to declare them as type float.

2006-09-15 02:29:52 · answer #1 · answered by justme 7 · 0 0

It's a little hard to answer because you haven't stated what the problem is, however...

int fToC is being given a real result - won't work.

output = BOILING_IN_F + " in Fahrenheit is " + fToC+ " in Celsius.";

You are not declaring the variable "output" anywhere that I can see. Should be throwing a compiler error, so I wonder if you have it declared somewhere else.

If this is in fact where your problem lies, just put a type in front of the line I quoted. String should do.

2006-09-15 01:20:20 · answer #2 · answered by Dan C 2 · 0 0

fToC = 5/9 * (BOILING_IN_F - 32);

The variable and the constant values are all of type int!
Thus 5/9 is equal to zero!

And so it continues....

I would certainly change the constants to float!

2006-09-15 04:15:33 · answer #3 · answered by AnalProgrammer 7 · 0 0

I wonder if order of operations is screwed up? What is the output you get from this? I'm just wondering if what's happening is sort of like

5 / (9 * (BOILING_IN_F - 32)) giving you some ridiculous number like 0.0031?

maybe try explicitly going (5/9) * (BOILING_IN_F -32)... or instead just using (BOILING_IN_F -32) / 1.8 ?

Of course if it's syntax... I'm don't know Java so someone else would have to help with that...

2006-09-14 19:12:10 · answer #4 · answered by wackydoodle119 1 · 0 0

it is -32 X 5 /9

2006-09-14 18:43:05 · answer #5 · answered by Anonymous · 0 0

i don't know java code but heres the math to convert C to F. F = (C x 9 / 5) +32.

2016-03-27 01:59:33 · answer #6 · answered by Sandra 4 · 0 0

fedest.com, questions and answers