forked from QUIET-DEVELOPER/Java-Programming-Internship
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperatureConverter.java
More file actions
42 lines (30 loc) · 1.16 KB
/
Copy pathTemperatureConverter.java
File metadata and controls
42 lines (30 loc) · 1.16 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
42
import java.util.Scanner;
public class TemperatureConverter {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter temperature value: ");
double temp = input.nextDouble();
System.out.print("Enter temperature scale (C, F, or K): ");
String scale = input.next();
double celsius;
switch(scale.toUpperCase()) {
case "C":
celsius = temp;
break;
case "F":
celsius = (temp - 32) * 5 / 9;
break;
case "K":
celsius = temp - 273.15;
break;
default:
System.out.println("Invalid temperature scale.");
return;
}
double fahrenheit = celsius * 9 / 5 + 32;
double kelvin = celsius + 273.15;
System.out.println("Celsius: " + celsius + " C");
System.out.println("Fahrenheit: " + fahrenheit + " F");
System.out.println("Kelvin: " + kelvin + " K");
}
}