forked from CSEdgeOfficial/Java-Programming-Internship
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemp_converter.java
More file actions
87 lines (73 loc) · 3.2 KB
/
Temp_converter.java
File metadata and controls
87 lines (73 loc) · 3.2 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.Scanner;
public class Temp_converter {
// Method to convert Celsius to Fahrenheit
public static double celsiusToFahrenheit(double celsius) {
return (celsius * 9/5) + 32;
}
// Method to convert Celsius to Kelvin
public static double celsiusToKelvin(double celsius) {
return celsius + 273.15;
}
// Method to convert Fahrenheit to Celsius
public static double fahrenheitToCelsius(double fahrenheit) {
return (fahrenheit - 32) * 5/9;
}
// Method to convert Fahrenheit to Kelvin
public static double fahrenheitToKelvin(double fahrenheit) {
return (fahrenheit - 32) * 5/9 + 273.15;
}
// Method to convert Kelvin to Celsius
public static double kelvinToCelsius(double kelvin) {
return kelvin - 273.15;
}
// Method to convert Kelvin to Fahrenheit
public static double kelvinToFahrenheit(double kelvin) {
return (kelvin - 273.15) * 9/5 + 32;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Temperature Converter");
System.out.println("=====================");
System.out.println("Choose the conversion type:");
System.out.println("1. Celsius to Fahrenheit");
System.out.println("2. Celsius to Kelvin");
System.out.println("3. Fahrenheit to Celsius");
System.out.println("4. Fahrenheit to Kelvin");
System.out.println("5. Kelvin to Celsius");
System.out.println("6. Kelvin to Fahrenheit");
int choice = scanner.nextInt();
System.out.print("Enter the temperature value: ");
double tempValue = scanner.nextDouble();
double convertedValue = 0;
switch (choice) {
case 1:
convertedValue = celsiusToFahrenheit(tempValue);
System.out.println(tempValue + " Celsius is equal to " + convertedValue + " Fahrenheit.");
break;
case 2:
convertedValue = celsiusToKelvin(tempValue);
System.out.println(tempValue + " Celsius is equal to " + convertedValue + " Kelvin.");
break;
case 3:
convertedValue = fahrenheitToCelsius(tempValue);
System.out.println(tempValue + " Fahrenheit is equal to " + convertedValue + " Celsius.");
break;
case 4:
convertedValue = fahrenheitToKelvin(tempValue);
System.out.println(tempValue + " Fahrenheit is equal to " + convertedValue + " Kelvin.");
break;
case 5:
convertedValue = kelvinToCelsius(tempValue);
System.out.println(tempValue + " Kelvin is equal to " + convertedValue + " Celsius.");
break;
case 6:
convertedValue = kelvinToFahrenheit(tempValue);
System.out.println(tempValue + " Kelvin is equal to " + convertedValue + " Fahrenheit.");
break;
default:
System.out.println("Invalid choice.");
break;
}
scanner.close();
}
}