Menu
Topics Index
...
`


Operators >
Siva Nookala - 12 Apr 2016
Learn Temperature Conversion Program In Java This program converts the temperature in Fahrenheit to Celsius. The formula used is C = 5.0 * (F - 32.0) / 9.0 .

Temperature conversion
class TemperatureConversion
{
    public static void main(String arg[])
    {
        double fahrenheit = 98.4;
        
        double celsius  = ( 5.0 * (fahrenheit - 32.0) ) / 9.0;
        
        System.out.println(fahrenheit + " F is same as " + celsius + " C.");
    
    }
}
OUTPUT

98.4 F is same as 36.888888888888886 C.

DESCRIPTION

Here we have declared a variable fahrenheit and initialized to 98.4. Then we are using the formula to convert from fahrenheit to celsius. And finally we are printing the result.

THINGS TO TRY
  • Change the fahrenheit value from 98.4 to 104.0 and see what is the output.
  • Change the program to convert from celsius to fahrenheit. The formula will be F = (( 9.0 * C ) / 5.0) + 32.0

0
Wrong
Score more than 2 points

© meritcampus 2016 - 2017

All Rights Reserved.