Changing values in variables with operators
Of course, in almost any program, we are going to need to "do things" with these variables' values. We manipulate (change) variables with operators. Here is a list of perhaps the most common Java operators that allow us to manipulate variables. You do not need to memorize them as we will look at every line of code as and when we use them for the first time. We have already seen the first operator when we initialized our variables, but we will see it again, this time being a bit more adventurous.
The assignment operator
This is the assignment operator: =
It makes the variable to the left of the operator the same as the value to the right—for example, like in this line of code:
unreadMessages = newMessages;
After the previous line of code has executed, the value stored in unreadMessages
will be the same as the value stored in newMessages
.
The addition operator
This is the addition operator: +
It...