Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Thread: Help With Temperature Converter (Beginner).

1. Help With Temperature Converter (Beginner).

Hi there.
Am just starting out with java and am having trouble to get this code to work. Its one of my exercises in my course and I've been trying to find a way to get it to work for a bit now (knowing me it will be something obvious i have overlooked). I can't seem to get the variable celsius into the convert method in order to proceed. I have been playing around but what I've tried doesn't seem to complete compilation. Any ideas would be greatly appreciated.

This is my first forum post and apologise in advance if formatting etc isn't correct.

Thanks.

```import java.util.Scanner;

public class FahrenheitToCelsius{

public static void main(String[]args){
convertFToC();
}
public static void convertFToC(){
Scanner scan = new Scanner(System.in);
System.out.println("Enter Fahrenheit temperature");
double fahrenheit = scan.nextDouble();
System.out.println(fahrenheit + " degrees Fahrenheit is" + celsius + "degrees Celsius");
}
public static double toCelsius (double fahr){
final int BASE = 32;
final double CONVERSION_FACTOR = 9.0 / 5.0;
final double CEL_CONVERSION_FACTOR = 5.0 / 9.0;
double celsius = fahr * CEL_CONVERSION_FACTOR - BASE;
return celsius;

}

}```

2. Re: Help With Temperature Converter (Beginner).

Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

At some point before the result is presented, you'd 'call' the toCelsius() method with the user's input:

double celsius = toCelsius( fahrenheit );

3. The Following User Says Thank You to GregBrannon For This Useful Post:

regsterbear (July 23rd, 2014)

4. Re: Help With Temperature Converter (Beginner).

Thanks for the help. Appreciate it a lot

5. Re: Help With Temperature Converter (Beginner).

You're welcome.