2.5.8 Using Variables in a Calculation

Line 23

sum = number1 + number2; // add numbers then store total in sum

is an assignment statement that calculates the sum of the variables number1 and number2 then assigns the result to variable sum by using the assignment operator, =. The statement is read as “sum gets the value of number1 + number2.” When the program encounters the addition operation, it performs the calculation using the values stored in the variables number1 and number2. In the preceding statement, the addition operator is a binary operator—its two operands are the variables number1 and number2. Portions of statements that contain calculations are called expressions. In fact, an expression is any portion ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.