Hunter McMillen wrote:A lot of books I've do stuff like this for formatting as well.
You need to know one thing to understand this kind of code: Java uses the
plus character, or
+, to assemble smaller strings into one longer one. A single println() call can only print one
String; if you want to print a number of things at once, you have to add them together to make one longer string first. So here we just want to print
3 + 2 = 5
we have to put five things together: the value of x, the symbol + with spaces around it, the value of y, the symbol = with spaces around it, and the value of z. We glue those together with the plus sign, and get
x + " + " + y + " = " + z
and then pass the whole thing to the println method.