With this code, the quantity of the variable result is 12. Based on Java™’s Order of Operations, addition (+) and subtraction (−) takes place after multiplication (×), division (÷), and modulos (%). Because of this, the formula first tackles “3 × 6”, which provides the int value 18. Next is “18 ÷ 4”; however, because the two variables are written as int values, the normal answer of 4.5 is rounded down to the nearest integer, being 4. After that is the operation “4 % 3”, meaning “Remainder of 4 ÷ 3”. The function “4 ÷ 3” has a remainder of 1. Finally, since one has gone through all the multiplication, division, and modulos in the problem, the addition and subtraction is addressed, going to the operation “13 − 1”, which is 12.
−Phoenix
Well done, just consider this one part and revise for technical accuracy, not rounding, but rather...?
ReplyDelete"the normal answer of 4.5 is rounded down to the nearest integer"
“…the normal answer of 4.5 is truncated to the nearest integer in the direction of 0, being 4.”
ReplyDelete−Phoenix
Yes, truncation involves simply ditching the fractional part, everything after the decimal is just dropped. Good work. 15 XPs awarded for this completion.
ReplyDelete