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