Of course, in almost any program, we are going to need to do things with these 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 being a bit more adventurous:
unreadMessages = newMessages;
.unreadMessages = newMessages + unreadMessages;
or accountBalance = yesterdaysBalance + todaysDeposits;
. Notice it is perfectly acceptable to use the same variable, simultaneously on both sides of an operator.unreadMessages = unreadMessages - 1;
or accountBalance = accountBalance - withdrawals;
.fairShare = numSweets / numChildren;
.answer = 10 * 10;
or biggerAnswer = 10 * 10 * 10;
.1
to something. myVariable = myVariable + 1;
is the same as myVariable ++;
.1
from something. myVariable = myVariable -1;
is the same as myVariable --;
.The formal names for these operators are slightly different to that previously explained. For example, the division operator is actually one of the multiplicative operators, but the names given previously are far more useful for the purpose of learning Java, and if you used the term division operator while conversing with someone from the Java community, they would know exactly what you mean.
There are actually many more operators than this in Java. We will meet a whole bunch more later in this chapter when we learn about decisions in Java.
If you are curious about operators, there is a complete list of them on the Java website here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html. All the operators required to complete the projects will be fully explained in this book. The link is provided for the curious among us.
3.129.249.105