Step-by-step explanation:
import java.util.Scanner;
public class Main{
public static float CtoF(float celsius)
{
return 9 * (celsius / 5) + 32;
}
public static float FtoC(float fahrenheit)
{
return (fahrenheit - 32) * 5 / 9;
}
public static void main(String []args){
System.out.println("Hello World");
float temperature;
Scanner in = new Scanner(System.in);
System.out.println("Enter temperature in Fahrenheit");
temperature = in.nextFloat();
System.out.println("Fahrenheit value = " + FtoC(temperature));
System.out.println("Enter temperature in Fahrenheit");
temperature = in.nextFloat();
System.out.println("Celcius value = " + CtoF(temperature));
}
}
In this program we get input through the scanner object and it needs "java.util.Scanner" header file. We are getting the relevant input and that input is passed on the relevant function which has the ability to convert to Celsius and Fahrenheit.
Formula:
To Fahrenheit: 9 * (celsius / 5) + 32;
To celcius: (fahrenheit - 32) * 5 / 9;