Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie to Java...please help

Status
Not open for further replies.

scampbell7

Programmer
Oct 14, 2006
1
0
0
US
I'm trying to take 2 values and compare them for eqaulity. I have a while loop for Fahrenheit temp's and I need to convert them to Celsius to see which temp is the same fo both. I did the formula out long hand and the answer is -40, now I just have to find a way to make the computer do it too!
here's the horrible mess I've made so far:


double tempF=0; //fahrenheit
float tempC=0; //Celsius


float counter = -100; //initiates count at -100 and gooes to +100
while(counter <= 100) {
tempF = counter; //stores each iteration of counter in tempF
tempC = (float)((5.0/9.0) * (tempF -32.0)); //converts Fahrenheit to Celsius
counter++;

}//ends while loop


if (tempC==(tempF)){
System.out.println("both Celsius and Farenheit have a common temperature at: " + ?????);
}//ends if
 
You are comparing a double with a float, try making both of them double or float
 
Futhermore, if you don't include the comparison into the while loop, it will be performed just once, at the end and with value 100.

Btw, there's a forum for standard Java questions: this one is for J2EE questions.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top