Question

In: Computer Science

System.out.println("Enter a temperature in Fahrenheit: ");          double fahrenheit = input.nextDouble();       double...

System.out.println("Enter a temperature in Fahrenheit: ");
     
   double fahrenheit = input.nextDouble();
  
   double celsius = (5.0 / 9) * (fahrenheit - 32);
   System.out.println("Fahrenheit " + fahrenheit + " is " + celsius + " in Celsius");

the above code i would like to print to 2 decimal places for celsius please  

this is in JAVA

Solutions

Expert Solution

please find your solution below and if any doubt comment and do upvote.

CODE:

import java.util.Scanner;
public class Main
{
        public static void main(String[] args) {
            Scanner input=new Scanner(System.in);
                System.out.println("Enter a temperature in Fahrenheit: ");
        double fahrenheit = input.nextDouble();
        double celsius = (5.0 / 9) * (fahrenheit - 32);
        //System.out.println("Fahrenheit " + fahrenheit + " is " + celsius + " in Celsius");
        //the is used to round off to twp decimal place System.out.printf("%.2f",value)
        //the .2 tell to print variable to 2 decimal place
        //for no precision remove the .2 or to increase or decrease precision add suitale number after .(dot) i.e .5,.1 etc 
        System.out.printf("Fahrenheit %.2f is %.2f in Celsius",fahrenheit,celsius);
        }
}

OUTPUT:


Related Solutions

In C Write a program that prompts the user to enter a Fahrenheit temperature calculate the...
In C Write a program that prompts the user to enter a Fahrenheit temperature calculate the corresponding temperature in Celsius and print it prompt the user if they want to do another temperature conversion if the user enters y, repeat 1), 2) and 3) if the user enters n, then print Bye and exit the program if the user enters any other character, ask the user to enter y or n only Note : c = (5.0/9.0)*(f-32.0) Sample output Enter...
struct TempScale { double fahrenheit; double centigrade; }; struct Reading { int windSpeed; double humidity; TempScale...
struct TempScale { double fahrenheit; double centigrade; }; struct Reading { int windSpeed; double humidity; TempScale temperature; }; Reading reading; // reading structure variable Write statements that will store the following data below, in the variable written above in C++ please Wind Speed: 37 mph Humidity: 32% Fahrenheit temperature: 32 degrees Centigrade temperature: 0 degrees
Write a Temperature class that will hold a temperature in Fahrenheit, and provide methods to get...
Write a Temperature class that will hold a temperature in Fahrenheit, and provide methods to get the temperature in Fahrenheit, Celsius and Kelvin. The class should have the following field: ftemp – A double that hold a Fahrenheit temperature. The class should have the following methods: Constructor – The constructor accepts a Fahrenheit temperature (as a double) and stores it in the ftemp field. setFahrenheit – The setFahrenheit method accepts a Fahrenheit temperature (as a double) and stores it in...
1. Temperature in kelvins (K) is related to the temperature in degrees Fahrenheit (°F) by the...
1. Temperature in kelvins (K) is related to the temperature in degrees Fahrenheit (°F) by the equation Design a MATLAB program that will do the following a. Prompt the user to enter an input temperature in °F. b. Read the input temperature. c. Calculate the temperature in kelvins in a separate function d. Write out the results with two digits to the right of the decimal (Use the fprintf function). The results should go to the command window.
Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin...
Temperature Converter Create a temperature conversion program that will convert the following to Fahrenheit: Celsius Kelvin Newton Your program should take a character which represents the temperature to convert from and a value to be converted to using the following specification: C - Celsius K - Kelvin N - Newton In addition your program should take in the following character to exit the program: X - eXit the program The numeric input for your program should be of type double....
Use the Excel directions below to create a scatterplot for the Temperature in Fahrenheit and the...
Use the Excel directions below to create a scatterplot for the Temperature in Fahrenheit and the number of cricket chirps per sec. Temp 88.6 71.6 92.3 85.3 80.6 75.2 69.7 81 69.4 83.3 79.6 82.6 80.6 (x) Chirps 20.5 16 19.8 18.4 17.1 15.5 14.7 17.1 15.4 16.2 15 17.2 16 (y) 3.) Find the linear regression equation using Excel. Slope uses the equation =slope(highlight y column, highlight x column). Y-intercept uses the equation =intercept(highlight y column, highlight x column)....
Use the Excel directions below to create a scatterplot for the Temperature in Fahrenheit and the...
Use the Excel directions below to create a scatterplot for the Temperature in Fahrenheit and the number of cricket chirps per sec. Temp 88.6 71.6 92.3 85.3 80.6 75.2 69.7 81 69.4 83.3 79.6 82.6 80.6 (x) Chirps 20.5 16 19.8 18.4 17.1 15.5 14.7 17.1 15.4 16.2 15 17.2 16 (y) 3.) Find the linear regression equation using Excel. Slope uses the equation =slope(highlight y column, highlight x column). Y-intercept uses the equation =intercept(highlight y column, highlight x column)....
Write a fragment of MIPS code to convert temperature in Kelvin to Fahrenheit
Write a fragment of MIPS code to convert temperature in Kelvin to Fahrenheit
Temperature Conversion Menu (100 pts) The three common temperature scales are Celsius, Fahrenheit and Kelvin. The...
Temperature Conversion Menu (100 pts) The three common temperature scales are Celsius, Fahrenheit and Kelvin. The conversion formulae for each of the scales is shown below (where °C, °F and K represent the temperatures in degrees Celsius, degrees Fahrenheit and Kelvin respectively): Celsius to Fahrenheit: °F = (9.0/5) ´ (°C) + 32 Celsius to Kelvin: K = °C + 273.15 Kelvin to Celsius: °C = K – 273.15 Kelvin to Fahrenheit: °F = (9.0/5) ´ (K – 273.15) + 32...
Develop a form to display centigrade temperature and corresponding Fahrenheit temperature ranging from 30 to 90...
Develop a form to display centigrade temperature and corresponding Fahrenheit temperature ranging from 30 to 90 at increments of 10. Use a do while loop. Please use the below formula to convert Celsius to Fahrenheit in advance C# I need the form not a table. Thank you!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT