Question

Write a program in java that generates a two-column table showing Fahrenheit temperatures from -40F to...

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 2 decimal place.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the required code:-

import java.util.*;
import java.text.DecimalFormat;


public class FahrenheitToCelsius {
  
private static DecimalFormat df = new DecimalFormat("0.00");
  
public static void main(String args[])
{
System.out.println("Fahrenheit Celsius\n");
  
for(double f=-40f; f<=120; f+=5)
{
double c = ((f - 32)*5)/9;
  
System.out.println(df.format(f) + " " + df.format(c));
}
  
}
}

This code produces the following output:-

Fahrenheit -40.00 -35.00 -30.00 -25.00 -20.00 -15.00 -10.00 -5.00 0.00 5.00 10.00 15.00 20.00 25.00 30.00 Celsius -40.00 -37.

Add a comment
Know the answer?
Add Answer to:
Write a program in java that generates a two-column table showing Fahrenheit temperatures from -40F to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT