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.

Respuesta :

Answer:

// program in java.

//package

import java.util.*;

// class definition

class Main

{

   // main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

       System.out.println("Fahrenheit \t celsius :");

       // print the temperature in Fahrenheit and equivalent celsius

       for(double f=-40;f<=120;f=f+5)

       {

           // convert Fahrenheit to equivalent celsius

           double cel=((f-32)*5)/9;

           // print the values

           System.out.printf("%.2f \t %.2f \n", f, cel);

       }

   

   }catch(Exception ex){

       return;}

}

}

Explanation:

Run a loop from -40 to 120.To convert a temperature from Fahrenheit to equivalent celsius we use formula cel=(f-32)5/9.This will convert the temperature from  Fahrenheit to celsius.increment 5 in Fahrenheit temperature and convert it to celsius till it reaches to 120.

Output:

Fahrenheit       celsius :                                                                                                

-40.00   -40.00                                                                                                            

-35.00   -37.22                                                                                                            

-30.00   -34.44

.

.

.

110.00   43.33                                                                                                            

115.00   46.11                                                                                                            

120.00   48.89

ACCESS MORE