In Java, doing simple arithmetic is very much like doing arithmetic in other languages such as Qbasic and Pascal using the +, -, * and / operators (plus, minus, times and divide). Often times, you will store the result of the mathematical expression in a variable. This is where the assignment operator is used.
The Assignment Operator (=)
For example the expression ...
x = y + z;
Math Operators (+, -, /, *, %)
Auto-incrementing and Auto-decrementing Variables
The most common mathematical formula used in programming languages is to take a variable add (or subtract) the value 1 to it and then store the result in the same variable.
In Java and many other programming Languages...
There are special operators to perform these actions.
For example:
1) if you have a variable x and you want to increment it, you would use this statement:
x++; // increases the value stored in x by one // This is the same as the statement x=x+1;
2) if you have a variable x and you want to decrement it, you would use this statement:
x--; // decreases the value stored in x by one // This is the same as the statement x=x-1;
Self-Assign operators
There are several self-assign operators ...
Example:
myMark += 10;
If myMark had the value 80 to start, it would have 90 after this statement was executed.