WAP to make a temperature converter based on user choice.
import java.util.*;
public class T7 {
public static void main(String[] args) {
int n;
double c, f;
Scanner sc = new Scanner(System.in);
System.out.print(
"Enter 1 for Centigrade to Fahrenheit Conversion and 2 for Fahrenheit to Centigrade Conversion: ");
n = sc.nextInt();
switch (n) {
case 1:
System.out.println("Enter value in Centigrade: ");
c = sc.nextDouble();
f = (9 * c) / 5 + 32;
System.out.println(f + " is the temperature in Fahrenheit.");
break;
case 2:
System.out.println("Enter value in Fahrenheit: ");
f = sc.nextDouble();
c = (f - 32) * 5 / 9;
System.out.println(c + " is the temperature in Centigrade.");
break;
default:
System.out.println("Enter choice 1 or 2!");
break;
}
}
}
Copy Code