运算符
算术运算符
long a
= 12121212121L
;
int b
= 123;
short c
= 10;
byte d
= 8;
System
.out
.println(a
+ b
+ c
+ d
);
System
.out
.println(b
+ c
+ d
);
System
.out
.println(c
+ d
);
int a
=10;
int c
=21;
System
.out
.println(c
%a
);
int a
=3;
int b
=a
++;
System
.out
.println(a
);
int c
=++a
;
System
.out
.println(a
);
double math
=Math
.pow(2,3);
System
.out
.println(math
);
关系运算符
int a
=10;
int b
=20;
System
.out
.println(a
>b
);
System
.out
.println(a
<b
);
System
.out
.println(a
==b
);
System
.out
.println(a
!=b
);
逻辑运算符
boolean a
= true;
boolean b
= false;
System
.out
.println("a&&b:"+(a
&&b
));
System
.out
.println("a||b:"+(a
||b
));
System
.out
.println("!(a&&b):"+!(a
&&b
));
int c
=5;
boolean d
=(c
<4)&&(c
++<4);
System
.out
.println(d
);
System
.out
.println(c
);
位运算符
System
.out
.println(2<<3);
条件问算符
int a
= 10;
int b
= 20;
a
+= b
;
System
.out
.println(a
);
a
-= b
;
System
.out
.println(a
);
字符串连接符 + ,String
int a
= 10;
int b
= 20;
System
.out
.println(""+a
+b
);
System
.out
.println(a
+b
+"");
三元运算符
int score
=80;
String type
=score
<60?"不及格":"及格";
System
.out
.println(type
);
运算符的优先级
表中结合性指运算符结合的顺序,通常都是从左到右。从右到左的运算符最典型的就是数值前面的正负号,例如3±4,则意义为3加-4,符号首先和运算符右侧的内容结合。
转载请注明原文地址:https://tech.qufami.com/read-12368.html