A
A
Artyom Kovalenko2020-10-15 14:41:39
Java
Artyom Kovalenko, 2020-10-15 14:41:39

"theTemperature* = 5/9" what is the difference between "theTemperature= theTemperature* 5/9"?

The bottom line is that when I write "theTemperature* = 5/9" it returns 0 for any value of the argument, and when I wrote "theTemperature= theTemperature* 5/9" - 5f8835366b4fb771069452.jpegeverything worked.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BorLaze, 2020-10-16
@ArtemHabrAccount

The difference is in the order of calculations.

int t = 20;
t = t * 5 / 9;
t *= 5 / 9;

In the first case, multiplication (20 * 5) is performed first, then division (100 / 9) - the result is 11.
In the second, (5 / 9) is first calculated, then 0 is multiplied by t.

T
Timur Pokrovsky, 2020-10-15
@Makaroshka007

theTemperature *= 5/9
So you multiply theTemperatureby the result of the integer division of 5 by 9.
Therefore, it will always be 0. 5 / 9

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question