Wednesday, September 23, 2009

Convert Celsius to Fahrenheit Java Code

The Java Code discussed today at Java Code Online deals with conversion of temperature from Celsius or Centigrade to Fahrenheit. The temperature conversions are required normally many times in our daily purposes. Like the body temperature in degree Fahrenheit and degree Celsius.

The only meeting point of these two temperature scales is -40 degree. At this temperature both the Celsius and the Fahrenheit scales are equal.

The Java code for this temperature conversion from Celsius to Fahrenheit is given below. The code requests the user to enter a temperature value in Celsius, and then displays the equivalent Fahrenheit Temperature.

package developer;

import java.util.Scanner;

public class CelsiusToFahrenheit {

    public static void main(String[] args) {

        System.out.println("Enter a temperature in Celsius: ");
        Scanner scanCelsius = new Scanner(;
        double Fahrenheit = 0;

        if (scanCelsius.hasNextDouble())
            Fahrenheit = (scanCelsius.nextDouble()*9) / 5 + 32;
        System.out.println("The temperature in Fahrenheit is: " + Fahrenheit);

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

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

Hope that the Java code provide for conversion from Celsius to Fahrenheit was beneficial to all. Keep checking Java Code Online for more Java updates and codes.

Related Java Code
Java Code to convert Fahrenheit to Celsius

No comments:

Post a Comment

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