算数运算符
+ :加法运算符
int a = 10;
int b = 20;
int sum = a + b;
// sum 的值为 30
System.out.println(sum);
- :减法运算符
int a = 20;
int b = 10;
int sum = a - b;
// sum 的值为 10
System.out.println(sum);
* :乘法运算符
int a = 10;
int b = 20;
int sum = a * b;
// sum 的值为 200
System.out.println(sum);
/ :除法运算符
int a = 10;
int b = 3;
int sum = a / b;
// sum 的值为 3
System.out.println(sum);
%:求余运算符
int a = 10;
int b = 3;
int sum = a %b;
// sum 的值为 1
System.out.println(sum);
++ :自加1
int a = 0;
int b = 0;
System.out.println(a);//0
System.out.println(b);//0
a++;
++b;
System.out.println(a);//1
System.out.println(b);//1
//++出现在变量右边,先做运算在自加1
System.out.println(a++);//1
//++出现前面左边,先自加1在运算
System.out.println(++b);//2
System.out.println(a);//2
System.out.println(b);//2
-- :自减1
用法与++基本相似