xhtml
 

Hint

You have probably written something like:

String result = m + " plus " + n + " is " + m+n;

The problem with this is that Java does the + operations from left to right, so after forming "23 plus 57 is " it then attaches the value of m to get "23 plus 57 is 23" and then attaches the value of n to get "23 plus 57 is 2357".

It is true that the last + operator has no spaces round it, and so looks to human eyes as if it should be done first. Java, though, takes no notice, and always ignores any unnecessary spacing (outside of double quotes). That means you have to put in brackets to make it clear to Java which operation to do first.


Back