Java program to convert celsius to fahrenheit
In this article, you will learn the Java program to convert units of measurement from
The boiling point of water is 100°C and the freezing point is 0°C on the Celsius scale, while the boiling point of water is 212°F and the freezing point is 32°F on the Fahrenheit scale.
Celsius to Fahrenheit
To convert temperatures in degrees Celsius to Fahrenheit, multiply by 1.8 (or 9/5) and add 32.
celsius * 1.8 = fahrenheit - 32
Algorithm
- Take temperature input from the user or define temperature in a Celsius unit.
- Apply the above formula to convert Celsius to Fahrenheit.
- Print the value in Fahrenheit.
Java program to convert Celsius to Fahrenheit
Here is a simple program to convert Celsius to Fahrenheit using the Java programming.
public class celsiustofahrenheit {
public static void main(String[] args)
{
// initialising variables
double celsius = 10.0, fahrenheit = 0.0;
// convert from celsius to fahrenheit
fahrenheit = (celsius * 1.8) + 32;
System.out.println(
" Temperature in Fahrenheit : "
+ fahrenheit);
}
}
Output of the above code:
Temperature in Fahrenheit : 50.0
Related Articles
nth prime number in JavaDeterminant of a matrix in Java
Find the greatest of three numbers in Java
Java random number between 1 and 10
Capitalize first letter of each word Java
Convert binary to decimal in Java
Convert decimal to binary in Java
Convert decimal to octal in Java
Convert decimal to hexadecimal in Java
Simple interest program in Java
Check whether the given number is even or odd in java
Print prime numbers from 1 to 100 in Java
Java prime number program
Fibonacci series program in Java
Java program to check leap year
Java program to find factorial of a number