Write a program to convert a Celsius temperature to a Fahrenheit temperature. Yo
ID: 3811054 • Letter: W
Question
Write a program to convert a Celsius temperature to a Fahrenheit temperature. Your program should have two methods: main method accepts from the user two input (positive or negative) integers that defines a range and calls the method cToF to generate a table of Celsius temperature from the lower bound to the upper bound of the range in increments of five degrees, with the Fahrenheit equivalents. cToF method with the header int cToF(int x) that converts a Celsius temperature to a Fahrenheit temperature. The conversion formula is F = (9.0/5.0)C + 32.Explanation / Answer
PROGRAM CODE:
package array;
import java.util.Scanner;
public class CelsiusToFahrenheit {
public static void cToF(int x)
{
double f = (9.0/5.0)*x + 32;
System.out.printf("%d %.2f ", x, f);
}
public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);
System.out.print("Enter the range: ");
int lower = kbd.nextInt();
int upper = kbd.nextInt();
System.out.println(" CELSIUS FAHRENHEIT ");
for(int i=lower; i<=upper; i=i+5)
{
cToF(i);
}
}
}
OUTPUT:
Enter the range: -10 30
CELSIUS FAHRENHEIT
-10 14.00
-5 23.00
0 32.00
5 41.00
10 50.00
15 59.00
20 68.00
25 77.00
30 86.00
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.