I am doing coding exercises right now and came across one task which I don’t know how to do, I also could not find any solution on the internet =(
For which assignment does the abbreviation stand: a *= 3 / 2? А) a = b + 3 / 2 B) a = a * 3 / 2 C) a + b - 3 / 2 D) a * b / 3 / 2 E) a = a * (3 / 2)
I know how =* and all alike compound operators work with a single number, but I don’t know how it works with a complex expression like 3 / 2. IntelliJ IDEA also runs into an error when trying to run “a *= 3 / 2”
Help me please =)
Advertisement
Answer
semantic of operator assignment in any programming language is as following:
lvalue *= rvalue => lvalue = lvalue * (rvalue)
Where rvalue can be any expression, therefore: a *= 3 / 2 => a = a * (3/2) -> answer is E
Read more about it here: https://www.cs.umd.edu/~clin/MoreJava/Intro/assign-compound.html