Write a program in java that generates a two-column table showing Fahrenheit temperatures from -40F to 120F and their equivalent Celsius temperatures. Each line in the table should be 5 degrees F more than the previous one. Both the Fahrenheit and Celsius temperatures should be accurate to 1 decimal place.
I am not able to use: import java.text.DecimalFormat;
Any feedback would be helpful.
Required Program in JAVA ->
public class Main {
public static void main(String[] args) {
System.out.println("Fahrenheit to Celsius-->"); //print
Fahrenheit to celsius on screen
double temp; //declare variable temp
for(temp = -40.0; temp <= 120; temp += 5) //for loop for temp
-40 to 120
{
System.out.printf("%.1f -----", temp); //display the value of temp,
to 1 decimal point
double cel = (temp -32) * (5.0/9.0); // find out the equivalent
celsius temp
System.out.printf(" %.1f", cel); //print the value of cel, to 1
decimal point
System.out.println(); //change the line
}
}
}
Get Answers For Free
Most questions answered within 1 hours.