Tuesday, September 22, 2009

Convert Fahrenheit to Celsius Java Code

Java Code Online has come up with a new Java Program, and that is for converting a temperature from Fahrenheit to Celsius or Centigrade. Fahrenheit and Celsius are the two main scales used for temperature measurement. The temperature of the normal human body is 98.4 degree Fahrenheit or 36.88 degree Celsius.

So temperature conversion is used normally in daily life. The only place where Fahrenheit and Celsius scales meet is at the temperature of -40 degree. That is to say that -40 degree Fahrenheit is equal to -40 degree Celsius.

The Java code for this temperature conversion from Fahrenheit to Celsius is given below. the code starts by asking the user to enter a temperature in Fahrenheit scale and then displays the equivalent Celsius Temperature.

package developer;

import java.util.Scanner;

public class FahrenheitToCelsius {

    public static void main(String[] args) {
        System.out.println("Enter a temperature in Fahrenheit: ");
        Scanner scanFaren = new Scanner(System.in);
        double Celsius = 0;
            Celsius = (scanFaren.nextDouble() - 32)*5/9;
        System.out.println("The temperature in Celsius is: "+Celsius);

When this Java Code was executed on my JVM, then the output was as shown below.

Enter a temperature in Fahrenheit:
The temperature in Celsius is: 13.333333333333334

Hope that the Java code provide for conversion from Fahrenheit to Celsius was useful to you all. Java Code Online will soon be back with another important Java Code.

Related Java Code:-
Java Code to convert Celsius to Fahrenheit

1 comment:

  1. Great code. I love your style of coding. Compact and precise. Keep posting new Java Codes, I need them for my Java Classes. Thanks a lot.


Note: Only a member of this blog may post a comment.