Program to convert temperature from Fahrenheit to Kelvin and vice-versa based on user choice.
Java
import java.util.*;
public class TemperatureFK
{
public static void main(String args[])
{
int choice=0;
double k,f=0.0;
Scanner sc=new Scanner(System.in);
System.out.println("1- To convert Fahrenheit to Kelvin");
System.out.println("2- To convert Kelvin to Fahrenheit");
System.out.print("Enter your choice: ");
choice=sc.nextInt();
switch(choice)
{
case 1:
{
System.out.print("Temperature in Fahrenheit: ");
f=sc.nextDouble();
k=((f-32)*5)/9;
k=k+273.15;
System.out.println("Temperature in Kelvin: "+k);
break;
}
case 2:
{
System.out.print("Temperature in Kelvin: ");
k=sc.nextDouble();
k=k-273.15;
f=((k*9)/5)+32;
System.out.println("Temperature in Fahrenheit: "+f+" °F");
break;
}
default:
{
System.out.println("Invalid Input");
}
}
}
}Java