Java Data Type Exercises: Fahrenheit to Celsius degree
Java Data Type: Exercise-1 with Solution
Write a Java program to convert temperature from Fahrenheit to Celsius degree.
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.
Java: Tips of the Day
How to sort an ArrayList?
Collections.sort(testList); Collections.reverse(testList);
That will do what you want. Remember to import Collections though!
Ref: https://bit.ly/32urdSe
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework