-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTempConversion.java
More file actions
41 lines (27 loc) · 1.1 KB
/
TempConversion.java
File metadata and controls
41 lines (27 loc) · 1.1 KB
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
31
32
33
34
35
36
37
38
39
40
41
import java.util.Scanner;
public class TempConversion {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double temp, newTemp;
char celsius, fahrenheit;
int choice;
System.out.println("1. Convert Celsius(C) to fahrenheit(F)");
System.out.println("2. Convert Fahrenheit(F) to Celsius(C)");
System.out.print("\nEnter your choice : ");
choice = scanner.nextInt();
if (choice == 1) {
System.out.print("\nEnter the temperature (C) : ");
temp = scanner.nextDouble();
newTemp = ((double) 9 / 5 * temp) + 32;
System.out.printf("%f C = %f F", temp, newTemp);
} else if (choice == 2) {
System.out.print("\nEnter the temperature (F) : ");
temp = scanner.nextDouble();
newTemp = (temp - 32) * ((double) 5 / 9);
System.out.printf("%f F = %f C", temp, newTemp);
} else {
System.out.println("Invalid Choice!");
}
scanner.close();
}
}