Question & Answer: Convert Celsius to Fahrenheit. (Programming Exercise 2.1) or Convert Fahrenheit to Celsius……

Convert Celsius to Fahrenheit. (Programming Exercise 2.1) or Convert Fahrenheit to Celsius.

Write a program with reads a Celsius degree value from the console or a Fahrenheit degree value from theconsole , then converts it to Fahrenheit or Celsius and displays the result. The formulas for the conversion are as follows:

Fahrenheit = (9 / 5) * Celsius + 32

Celsius = (5/9) *(Fahrenheit -32)

Write this program in Java please

Expert Answer

 

import java.util.Scanner;

public class Temperature {

public static void main(String[] args) {
double tempFahrenheit;
Scanner sc = new Scanner(System.in);
System.out.print(“Enter the temperature in Fahrenheit: “);
tempFahrenheit = sc.nextDouble();
double tempCelcius = (tempFahrenheit – 32) * 5 / 9.0;
System.out.println(tempFahrenheit + ” in Fahrenheit is ” + tempCelcius + ” in Celsius”);

System.out.print(“nnEnter the temperature in Celcius: “);
tempCelcius = sc.nextDouble();
tempFahrenheit = (32 + (tempCelcius * 9 / 5.0));

System.out.println(tempCelcius + ” in Celsius is ” + tempFahrenheit + ” in Fahrenheit”);

}
}
====================
See Output

Still stressed from student homework?
Get quality assistance from academic writers!