27.8k views
1 vote
Write a method to convert from Celsius to Fahrenheit using the following method header:// convers form Celsius to Fahrenheitpublic static double celsiusToFahrenheit (double celsius)The formula for the conversion is: Fahrenheit = ( 9/5) * Celsius +32

User Ryuman
by
5.6k points

1 Answer

2 votes

Answer:

public class Main

{

public static void main(String[] args) {

System.out.println(celsiusToFahrenheit(10));

}

public static double celsiusToFahrenheit (double celsius){

double fahrenheit = (9/5.0) * celsius + 32;

return fahrenheit;

}

}

Step-by-step explanation:

Create a method named celsiusToFahrenheit that takes one parameter, celsius

Inside the method:

Convert the celcius to fahrenheit using the given formula. Note that, in the formula 9/5 is integer division. You need to convert it to the double so that the result should not be 0. One solution is converting one of the int to decimal, 9/5 → 9/5.0

Return the fahrenheit

Inside the main method:

Call the celsiusToFahrenheit() with some value and print the result

User Sam Parrish
by
5.2k points