java exercise - temperature conversion

1

Temperature conversion (5 points)

Topic content:

Write a program to convert Fahrenheit to Celsius. The conversion formula is:

    °F = (9/5)*°C + 32

Where C stands for Celsius and F stands for Fahrenheit.

The input to the program is an integer representing the temperature in Fahrenheit. Output the corresponding temperature in Celsius, also an integer.

As a reminder, in order to convert the floating-point number of the calculation result into an integer, the following expression needs to be used:

    (int)x;

where x is the floating point number to be converted.

 

Note: In addition to the output required by the title, you cannot output any other content, such as prompts when inputting, instructions when outputting, etc. This question requires the converted number, and the program can only output this number, and nothing else can be output.

 

Input format:

an integer.

 

Output format:

an integer.

 

Input sample:

100

 

Sample output:

37

Time limit: 500ms Memory limit: 32000kb

 int F;
 final int range =32;
 F  = in.nextInt();
 double result = (F - range)/(9/5.0);
 System.out.println((int)result);
       

 

Guess you like

Origin blog.csdn.net/qq_39711485/article/details/112394854