Answer:
Output
Temperature Converter
C-----From Celsius to Fahrenheit
F-----From Fahrenheit to Celsius
Enter your choice (C or F):
C
Enter temperature in Celsius:
45
Temperature in Fahrenheit: 113.0 °F
Step-by-step explanation:
Below given is a java code that will convert Celsius to Fahrenheit or the other way:-
import java.util.Scanner;
public class TemperatureConvertor {
public static void main(String[] args){
double celsius=0.0;
double fahrenheit=0.0;
String choice;
Scanner input=new Scanner(System.in);
System.out.println("Temperature Convertor");
System.out.println("C-----From Celsius to Fahrenheit");
System.out.println("F-----From Fahrenheit to Celsius");
System.out.println("Enter your choice (C or F): ");
choice=input.next();
if(choice.equals("C")){
System.out.println("Enter temperature in Celsius: ");
celsius=input.nextDouble();
fahrenheit=((9*celsius)/5)+32;
System.out.println("Temperature in Fahrenheit: "+fahrenheit+" °F");
}else if(choice.equals("F")){
System.out.println("Enter temperature in Fahrenheit: ");
fahrenheit=input.nextDouble();
celsius=(5*(fahrenheit-32))/9;
System.out.println("Temperature in Celcius: "+celsius+" °C");
}else{
System.out.println("Wrong choice !!!");
}
}
}