Arithmetic Operations – Intro to Java Programming


These should have given 42, 16 and 4. This last one should have surprised you if you haven’t coded before. Mostly Java follows the same rules that you learn in algebra. Here x is 3 and y is 4. Multiplication happens before addition and then we add 4 to 3 and get 7. 2 and 4 gives us 6 and we multiply it to get 42. It’s possible that your algebra sense took over here and you read xy as x times y. But it should actually be 11 because xy is a variable. Then y over 2 and 3, 3 and 2 and 11 gives us 16. For this last one it kind of looks like Java just miscalculated. I would’ve expected this to be 4 plus 5, which is 9 over 2. Which would be 4.5. Let’s go back to Cay to talk about what happened.

5 thoughts on “Arithmetic Operations – Intro to Java Programming

Leave a Reply

Your email address will not be published. Required fields are marked *