Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that converts a temperature from Fahrenheit to Celsius. It should do the following: Prompt the user for input Read adouble value from



Write a program that converts a temperature from Fahrenheit to Celsius.

It should do the following:

  1. Prompt the user for input
  2. Read adouble value from the keyboard
  3. Calculate the result.Here is the formula: C = (F - 32) * 5 / 9
  4. Format the output to one decimal place.

Your prompt to the user to enter the temperature in Celsius must be:

Enter the Fahrenheit Temperature as a decimal:

Your output must be of the format:

fahrenheitTemperature F =celsiusTemperature C

A sample run with input 75.2 must look like:

Enter the temperature in degrees celsius: 75.2

75.2 F = 24.0 C

A sample run with input 7.5 must look like:

Enter the temperature in degrees celsius: 7.5

7.5 F = -13.6 C

Hint1:Be careful not to use integer division! Here is the formula again:C = (F - 32) * 5 / 9

Hint2: Remember to use printf to format the output.

Please make sure to end each line of output with anewline.

Please note that your class should be namedFahrenheitToCelsius.

What I wrote:


import java.util.Scanner; public class FahrenheitToCelsius {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter the Fahrenheit Temperature as a decimal:"); double fahrenheit = input.nextDouble();

double celsius =(( 5 *(fahrenheit - 32.0)) / 9.0); System.out.println("%.1f = ", tempfahrenheit); System.out.println("%.1f = ", tempcelsius); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Here is an improved version of your FahrenheitToCelsius program that correctly handles the con... blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Starting Out With Java From Control Structures Through Data Structures

Authors: Tony Gaddis

6th Edition

0133957055, 978-0133957051

Students also viewed these Programming questions

Question

Describe a programming problem requiring the use of nested loops.

Answered: 1 week ago