-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavalab2.java
More file actions
34 lines (27 loc) · 970 Bytes
/
Copy pathjavalab2.java
File metadata and controls
34 lines (27 loc) · 970 Bytes
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
import java.util.Scanner;
public class javalab2
{
public static void main(String[] args)
{
double converted;
Scanner sr = new Scanner(System.in);
System.out.print("Enter temperature scale (F for Fahrenheit, C for Celsius): ");
String ch = sr.nextLine().toUpperCase(); // Convert input to uppercase for uniformity
System.out.print("Enter temperature value: ");
double temp = sr.nextDouble();
switch (ch)
{
case "F":
converted = (temp - 32) * (5.0 / 9);
System.out.println("Temperature in Celsius: " + converted);
break;
case "C":
converted = (1.8 * temp) + 32;
System.out.println("Temperature in Fahrenheit: " + converted);
break;
default:
System.out.println("Invalid input! Please enter 'C' or 'F'.");
}
sr.close();
}
}