77.2k views
5 votes
(temperature converter app) write an app that performs temperature conversions. the app should perform two types of conversions: degrees fahrenheit to degrees celsius, and degrees celsius to degrees fahrenheit. to convert degrees fahrenheit to degrees celsius, use this formula: celsius

1 Answer

2 votes

Answer:

Sure, here's an example of a temperature converter app that performs conversions between Fahrenheit and Celsius:

```

import java.util.Scanner;

public class TemperatureConverter {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("Temperature Converter");

System.out.println("1. Fahrenheit to Celsius");

System.out.println("2. Celsius to Fahrenheit");

System.out.print("Enter your choice (1 or 2): ");

int choice = scanner.nextInt();

System.out.print("Enter temperature: ");

double temperature = scanner.nextDouble();

if (choice == 1) {

double celsius = (5.0 / 9.0) * (temperature - 32.0);

System.out.println(temperature + "F = " + celsius + "C");

} else if(choice == 2) {

double fahrenheit = (9.0 / 5.0) * temperature + 32.0;

System.out.println(temperature + "C = " + fahrenheit + "F");

} else {

System.out.println("Invalid choice!");

}

}

}

```

This app first displays a menu with two options for converting Celsius to Fahrenheit or Fahrenheit to Celsius. The user is then prompted to enter their choice and the temperature to be converted. The formulas for converting Fahrenheit to Celsius and Celsius to Fahrenheit are applied depending on the user's choice and the result is displayed to the user.

User Biruk Abebe
by
8.4k points