Java: Fahrenheit to Celsius degree
Java Data Type: Exercise-1 with Solution
Convert Fahrenheit to Celsius
Write a Java program to convert temperature from Fahrenheit to Celsius degrees.
The Fahrenheit scale is a temperature scale based on one proposed in 1724 by physicist Daniel Gabriel Fahrenheit. It uses the degree Fahrenheit (symbol: °F) as the unit.
The Celsius scale, previously known as the centigrade scale, is a temperature scale used by the International System of Units (SI). As an SI derived unit, it is used by all countries in the world, except the U.S.
Test Data
Input a degree in Fahrenheit: 212
Sample Solution:
Java Code:
import java.util.Scanner;
public class Exercise1 {
public static void main(String[] Strings) {
Scanner input = new Scanner(System.in);
System.out.print("Input a degree in Fahrenheit: ");
double fahrenheit = input.nextDouble();
double celsius =(( 5 *(fahrenheit - 32.0)) / 9.0);
System.out.println(fahrenheit + " degree Fahrenheit is equal to " + celsius + " in Celsius");
}
}
Sample Output:
Input a degree in Fahrenheit: 212 212.0 degree Fahrenheit is equal to 100.0 in Celsius
Flowchart:
Java Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Data Types Exercises
Next: Write a Java program that reads a number in inches, converts it to meters.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/java-exercises/datatypes/java-datatype-exercise-1.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics