In this tutorial you will learn about the Java Program to Convert Fahrenheit to Celsius and its application with practical example.
In this tutorial, we will learn to create a Java program that will Convert Fahrenheit to Celsius using Java programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following c programming topics:
- Java Operators.
- Basic Input and Output
- Class and Object.
- Basic Java programming.
- Looping statements.
What Is Temperature ?
Temperature is a quantity that is use to measure the freezing and the boiling point of water. Which is measured by different scales in different regions like Celsius and Fahrenheit.
In Celsius scale, the boiling point of water is 100°C, and the freezing point is at 0°C, while in the Fahrenheit scale the boiling point of water is 212°F and freezing point is at 32°F.
Java Program to Convert Fahrenheit to Celsius
In this program we will convert temperature from Fahrenheit to Celsius. We would first declared and initialized the required variables. Next, we would prompt user to input the value in Fahrenheit. Later we will Convert the values into Celsius.
To convert values from Fahrenheit to Celsius we will use following Formula:
C = (F – 32)*(5/9)where, F is temperature in Fahrenheit and C is temperature in Celsius.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import java.util.Scanner; public class Fahrenh_to_Celsisu { public static void main(String[] Strings) { double f,c; // declaring variables.. Scanner input = new Scanner(System.in); System.out.print("Input value in Fahrenheit: "); f = input.nextDouble(); // taking values from user... c =(( 5 *(f - 32.0)) / 9.0); // Calculating Celsius // Printing the result.. System.out.println(f + " Degree Fahrenheit is equal to = " + c + " in Celsius"); } } |
Output
Concept to find Fahrenheit to Centigrade.
First of all we will take the value in Fahrenheit temperature.
Then we will calculate c = 5 * (f – 32) / 9.
Print Celsius C.
In the above program, we have first declared and initialized a set variables required in the program.
- f = it will hold Fahrenheit value.
- c= it will hold Celsius value.
And in the next statement user will be prompted to enter value in Fahrenheit and which will be assigned to variable ‘f’.
After that with the formula we will convert the value of Fahrenheit to Celsius.
As you can see in above program, we first take value in Fahrenheit as input from user. Then convert the value of Fahrenheit in to Celsius using above conversion equation and print the Temperature in Celsius.