Solution - Celsius To Fahrenheit

Problem. Write a method called convertToFahrenheit that takes a double parameter representing a temperature in Celsius and returns the temperature in Fahrenheit. Use the formula Fahrenheit = (Celsius * 9/5) + 32. Call the method from the main method and display the result in the console.

Solution.

TemperatureConversion.java

public class TemperatureConversion {
  public static void main(String[] args) {
    double celsius = 30.0;
    double fahrenheit = convertToFahrenheit(celsius);
    System.out.println("Temperature in Fahrenheit: " + fahrenheit);
  }

  public static double convertToFahrenheit(double celsius) {
    return (celsius * 9/5) + 32;
  }
}