The following is
the example we used in previous lesson.
1. class
variable
2. {
3. public static void main(String[]
args)
4. {
5. int HisBooks=30;
6. int MyBooks=40;
7. int TotalBooks=HisBooks+MyBooks;
8. System.out.println("Total
books we have="+TotalBooks);
9. }
10. }
We used int variables in the above
code. In Line 7 ,we used Arithmetic Operators +.
Arithmetic Operators
Arithmetic Operators is very similar to what
you learn from school. Only a little bit difference. For example,
you use ÷ for
divide, I use / for
divide.
(Since there is no such ÷ key
in my keyboard. :>)
I use * for
multiplication.
| Operator |
Sign |
Example |
| Addition |
+ |
3+2 |
| Subtraction |
- |
5-3 |
| Multiplication |
* |
2*5 |
| division |
/ |
18/3 |
| remainder |
% |
7%4=3 |
|