Java Program to Convert Centigrade to Fahrenheit

Java program to convert centigrade to fahrenheit can be implemented by using following formula


$F = 32+\frac{9*C}{5}$


Here, value of $F$ is the temperature in fahrenheit while $C$ is the temperature in centigrade.

Fahrenheit and Centigrade are two well known temperature scales. Both of them are used regularly in daily temperature measurements. By using above formula, the following Java program produces output in fahrenheit ($^{\circ}F$) while taking centigrade ($^{\circ}C$) as input.






1. Java Program & output to convert centigrade to fahrenheit

Code has been copied
/************************************************
            alphabetacoder.com
 Java program to convert Centigrade to Fahrenheit
**************************************************/

import java.util.Scanner;
public class Temperature{
    public static void main(String args[]){
    
        double f,c;

        // declare an instance of Scanner class
        Scanner sc = new Scanner(System.in);
        //take input in fahrenheit
        System.out.print("Enter the temperature in centigrade = ");
        c = sc.nextDouble();
        
        //convert fahrenheit and c
        f = 32 + (9 * c) / 5;
        
        System.out.print("Temperature is "+f+" in fahrenheit When "+c+" in centigrade.");
    }
}

Output


Enter the temperature in centigrade = 30

Temperature is 86.0 in fahrenheit When 30.0 in centigrade.