Write a program to convert a Celsius temperature to a Fahrenheit temperature. Yo
ID: 3811092 • 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
Hi, Please find my implementation.
Please let me know in case of any issue.
import java.util.Scanner;
public class CelciusToFahrenheit {
public static int cToF(int x){
return (int)((9.0/5.0)*x + 32);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter lower range: ");
int lower = sc.nextInt();
System.out.print("Enter higher range: ");
int higher = sc.nextInt();
System.out.println("C F");
for(int i=lower; i<=higher; i+=5)
System.out.println(i+" "+cToF(i));
}
}
/*
Sample run:
Enter lower range: -8
Enter higher range: 12
C F
-8 17
-3 26
2 35
7 44
12 53
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.