88.2k views
1 vote
5) Create Java program that converts from Fahrenheit to

Celsius and from Celsius to Fahrenheit. The formula for
the conversion is C/5 = (F-32)/9.

User Brian Lacy
by
6.9k points

2 Answers

1 vote

Answer:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

double celsius;

double fahrenheit;

double formula;

Scanner sc = new Scanner(System.in);

System.out.println("-------FAHRENHEIT TO CELSIUS CONVERTER-------");

System.out.print("Enter the fahrenheit value to be converted: ");

fahrenheit = sc.nextDouble();

celsius = 5 * ((fahrenheit-32) / 9);

System.out.printf("The converted fahrenheit value is: %.2f", celsius);

}

}

Step-by-step explanation:

since 5 is dividing celsius, you can throw it to the other side multiplying the rest of the equation.

User Blueseal
by
7.0k points
5 votes

Answer: class TemperatureConverter {

public static double

fahrenheitToCelsius(double fahrenheit) {

return (fahrenheit - 32) * (5.0 / 9.0);

}

public static double celsiusToFahrenheit(double celsius) {

return (celsius * (9.0 / 5.0)) + 32;

}

public static void main(String[] args) {

double fahrenheit = 77.0;

double celsius = 25.0;

System.out.println(fahrenheit + " degrees Fahrenheit is " + fahrenheitToCelsius(fahrenheit) + " degrees Celsius.");

System.out.println(celsius + " degrees Celsius is " + celsiusToFahrenheit(celsius) + " degrees Fahrenheit.");

}

}

Step-by-step explanation:

User Gawel
by
7.3k points