Home Lifestyle Java Program to Convert Celsius to Fahrenheit (updated)

# Java Program to Convert Celsius to Fahrenheit (updated)

117
0

Java Program to Convert Celsius to Fahrenheit (updated) – Conversion from Celsius to Fahrenheit and from Fahrenheit to Celsius has an important role in the conversion of units system. In this post, we will develop a Java program to convert Celsius to Fahrenheit.

The formula used to convert from Celsius to Fahrenheit is given as,

## Java Program to Convert Celsius to Fahrenheit

``````

import java.util.Scanner;

public class TemperatureConversion {
// method to convert celsius to fahrenheit
private static double tofahrenheit(double celsius){
return ( celsius * (9.0/5.0) + 32 );
}

public static void main(String[] args) {

// declare variables
double celsius = 0.0;
double fahrenheit = 0.0;

// create Scanner class object to read input
Scanner scan = new Scanner(System.in);

System.out.print("Enter Celsius value:: ");
celsius = scan.nextDouble();

// convert temperature
fahrenheit = tofahrenheit(celsius);

// display result
System.out.println("Fahrenheit value = "
+fahrenheit);

// close Scanner class object
scan.close();
}
}
The output for different test-cases:-

``````

## OUTPUT

``````

Enter Celsius value:: 15
Fahrenheit value = 59.0

``````