-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemperatureConverter.java
31 lines (25 loc) · 1.26 KB
/
TemperatureConverter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
public class TemperatureConverter {
public static void main(String[] args) {
System.out.println("TEMPERATURE CONVERTER");
System.out.println("1. CONVERT CELSIUS TO FAHRENHEIT");
System.out.println("2. CONVERT FAHRENHEIT TO CELSIUS");
System.out.print("ENTER YOUR CHOICE (1 OR 2): ");
Scanner input = new Scanner(System.in);
int choice = input.nextInt();
if (choice == 1) {
System.out.println("Enter temperature in Celsius: ");
double tempCelsius = input.nextDouble();
double tempFahrenheit = (tempCelsius * 9.0 / 5) + 32;
System.out.println(tempCelsius + "°C is equal to " + tempFahrenheit + "°F");
} else if (choice == 2) {
System.out.println("Enter temperature in Fahrenheit: ");
double tempFahrenheit = input.nextDouble();
double tempCelsius = (tempFahrenheit - 32) * 5.0 / 9;
System.out.println(tempFahrenheit + "°F is equal to " + tempCelsius + "°C");
} else {
System.out.println("Invalid choice! Please select 1 or 2.");
}
input.close();
}
}