Program that Converts Fahrenheit to Celsius
927746Apr 1 2012 — edited Apr 2 2012Hello all,
I am brand new to the forum, so please advise me if I am posting a new thread "illegally" based on the forum rules.
I am creating a program for class that converts Fahrenheit to Celsius using a method called in a loop. Here is the question:
The formula for converting a temperature from Fahrenheit to Celsius is C = 5/9 * (F - 32), where F is the Fahrenheit temperature and C is the Celsius temperature. Write a method named celsius that accepts a Fahrenheit temperature as an argument. The method should return the temperature, converted to Celsius. Demonstrate the method by calling it in a loop that displays a table of the Fahrenheit temperatures 0 through 20 and their Celsius equivalents.
Here is the code that I have thus far:
public class ConvertTemp
{
public static void main(String[] args)
{
System.out.println("Fahrenheit\tCelsius");
System.out.println("=========================");
celsius();
}
// Create the celsius method.
public static double celsius(int F, double C)
{
for(F = 0; F <= 20; F++){
C = (5.0 / 9.0) * (F - 32.0);
return C;
}
}
}
When I attempt to compile, I get the following error message: "method celsius in class ConvertTemp cannot be applied to given types". Does this mean that the arguments int F and double C that I passed in the celsius method are not the correct data type to be returned to the main method?
Any help is much appreciated!
Thank you