Java运算符
- 运算符
种类 |
描述 |
算术运算符 |
+ - * / % ++ -- |
赋值运算符 |
= |
关系运算符 |
> < >= <= == != instanceof |
逻辑运算符 |
&& || ! |
位运算符 |
& | ^ ~ >> << >>> |
条件运算符 |
? : |
拓展运算符 |
+= -= *= /= |
https://www.runoob.com/java/java-operators.html
- 注意点(important)
- + 计算中,如果参与计算有long型则输出为long,否则为int
long num1 = 123123123123L;
int num2 = 123;
short num3 = 12;
byte num4 = 1;
System.out.println(num1 + num2 + num3); // ==> long
System.out.println(num2 + num3); // ==> int
System.out.println(num3 + num4); // ==> int
int a = 1;
int b = 2;
String c = "计算";
System.out.println(c + a + b); // ==> 计算12
System.out.println(a + b + c); // ==> 3计算