Java Fahrenheit to Celsius Conversion

JavaJavaBeginner
Practice Now

Introduction

Welcome to WeatherTech, the leading meteorological software company in JavaLand! As a new intern, you've been tasked with an important mission: to help create a temperature conversion tool for the upcoming JavaLand Weather App.

The chief meteorologist, Dr. Sunny Skies, has noticed that many visitors from countries using Celsius are confused by Fahrenheit temperatures. Your job is to complete a simple Java program that converts Fahrenheit to Celsius, making temperature readings clear for all JavaLand tourists!

Are you ready to make JavaLand's weather accessible to everyone? Let's dive in and start coding!


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL java(("`Java`")) -.-> java/ObjectOrientedandAdvancedConceptsGroup(["`Object-Oriented and Advanced Concepts`"]) java(("`Java`")) -.-> java/BasicSyntaxGroup(["`Basic Syntax`"]) java/ObjectOrientedandAdvancedConceptsGroup -.-> java/user_input("`User Input`") java/BasicSyntaxGroup -.-> java/data_types("`Data Types`") java/BasicSyntaxGroup -.-> java/math("`Math`") java/BasicSyntaxGroup -.-> java/operators("`Operators`") java/BasicSyntaxGroup -.-> java/output("`Output`") java/BasicSyntaxGroup -.-> java/variables("`Variables`") subgraph Lab Skills java/user_input -.-> lab-413851{{"`Java Fahrenheit to Celsius Conversion`"}} java/data_types -.-> lab-413851{{"`Java Fahrenheit to Celsius Conversion`"}} java/math -.-> lab-413851{{"`Java Fahrenheit to Celsius Conversion`"}} java/operators -.-> lab-413851{{"`Java Fahrenheit to Celsius Conversion`"}} java/output -.-> lab-413851{{"`Java Fahrenheit to Celsius Conversion`"}} java/variables -.-> lab-413851{{"`Java Fahrenheit to Celsius Conversion`"}} end

Complete the Temperature Conversion Program

In this exercise, you'll be implementing a fundamental tool used in everyday life and scientific applications: converting temperatures from Fahrenheit to Celsius. This task will help you practice working with user input, mathematical operations, and formatting output in Java. Let's dive in and make those temperatures more globally understood!

Tasks

  • Open the pre-created file FahrenheitToCelsius.java in the ~/project directory.
  • Find the TODO comment in the code.
  • Add the line of code that performs the Fahrenheit to Celsius conversion.

Requirements

  • The file FahrenheitToCelsius.java should already exist in the ~/project directory.
  • You should only add one line of code where the TODO comment is.
  • Use the formula: Celsius = (Fahrenheit - 32) * 5 / 9
  • The result should be stored in the celsius variable.

Example

When completed correctly, your program should work like this when run:

cd ~/project
javac FahrenheitToCelsius.java 
java FahrenheitToCelsius

Sample Output:

Temperature in Fahrenheit: 98.6
98.6°F is equal to 37.0°C
✨ Check Solution and Practice

Summary

In this challenge, you've completed a Java program that converts temperatures from Fahrenheit to Celsius. This exercise reinforced key concepts from your Java Data Types and Basic Operations lab:

  1. Working with floating-point numbers (double)
  2. Performing arithmetic operations in Java
  3. Using variables to store and manipulate data
  4. Formatting output with printf

By completing this challenge, you've not only practiced these fundamental Java skills but also created a useful tool that could help visitors to JavaLand understand local weather reports more easily.

Other Java Tutorials you may like