Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Program that Converts Fahrenheit to Celsius

927746Apr 1 2012 — edited Apr 2 2012
Hello 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 30 2012
Added on Apr 1 2012
8 comments
5,677 views