[JAVA] Programming learning record 89-Fahrenheit temperature to Celsius temperature-

What i did today

--Write a program that converts the Fahrenheit temperature to Celsius temperature and displays it.

This is an assignment that was given in a Java lecture at a university.

I can't publish what kind of code I wrote because it's an issue, but I'll write it down somehow.

First, in Java, when declaring a variable, you have to change the reserved word depending on the display format even for the same number such as integer type and real number type.

This time, it was necessary to display up to the first decimal place, so I declared it as a real number. In Java, declare a real number with double.

The declared variables are Fah and Cel, and Fah is assigned the Fahrenheit temperature and Cel is assigned the Celsius temperature.

First, write the code to input the Fahrenheit temperature, convert the input Fahrenheit temperature to the Celsius temperature, and substitute it for Cel.

The formula for converting Fahrenheit temperature to Celsius temperature is as follows.

C=(5/9)×(F-32)

This formula allows us to express the Fahrenheit temperature in the unit of temperature we usually use (° C).

And finally, if you can display Cel with the following code, you are done.

System.out.printf("Temperature Celsius (℃)%.1f\n",Cel);

You can display real numbers up to the first decimal place with 1f \ n and start a new line.

There are various Java-specific rules, but the idea is basically the same, so I managed to clear it.

end

Recommended Posts

Programming learning record 89-Fahrenheit temperature to Celsius temperature-
Programming learning day 3
My learning record
How to organize information to make programming learning more efficient
SPRING BOOT learning record 01
SPRING BOOT learning record 02
Introduction to Practical Programming