-
算术运算符:+,-,*,/,%,++,--
-
package com.yan.Operator; public class Dome001 { public static void main(String[] args) { //两位数的运算叫做二元运算符 //Ctel+d 复制到下一行 int a = 10 ; int a1 = 20 ; int a2 = 25 ; int a3 = 20 ; System.out.print(a+a1); System.out.print(a-a2); System.out.print(a*a3); System.out.print(a/(double)a3); //不同类型计算,向计算单位中最高位转换 byte byte1 = 8; short short1 = 176; int int1 = 21005; long long1 = 121561; double double1 = 3.1415; System.out.print(byte1+short1+int1+long1+double1); System.out.print(byte1+short1+int1+long1); System.out.print(byte1+short1+int1); System.out.print(byte1+short1); System.out.print(byte1>=short1); System.out.print(byte1<=short1); System.out.print(byte1==short1); } }
-
赋值运算符:= a=10;(把10赋值给a这个变量)
-
关系运算符:<,>,>=,<=,==,=!, instanceof
-
逻辑运算符:&&(什么与什么),||(什么或什么),!(不等,非)
-
package com.yan.Operator; public class Dome003 { public static void main(String[] args) { boolean a = true; boolean b = false; //&&:与 真假 为 假 。 真真为真 System.out.print("a&&b:"+(a&&b)); //||:或(并集) 真假 为真 。 System.out.print("a||b:"+(a||b)); //!:非(与&&相反的) true && true 为真。 !(true && true) 为假 System.out.print("!(a&&b)"+!(a&&b)); //短路运算 int c = 1 ; boolean d = ((c>4)&&(c++<3)); System.out.print(c); System.out.print(d); } }
-
位运算符:&,|,^,~,>>,<<,>>>
-
条件运算符:?
-
package com.yan.Operator; public class Dome005 { public static void main(String[] args) { //三目运算符 //x?y:z 如果x = true,则为y,否则为z int score = 59; String type = score<60?"不及格":"及格"; System.out.print(type); int result = 1 ; String type1 = result != 1 ?"工资2500":"回家养猪"; System.out.print(type1); } }
-
扩展赋值运算符:+=,-=,*=,/=
package com.yan.Operator; public class Dome002 { //自增++ a++(先用后增) ++a(先增后用) public static void main(String[] args) { int a = 1; int b = a++; System.out.print(b); int c = ++a; System.out.print(a); //System.out.print(b); System.out.print(c); //幂运算 double d = Math.pow(2,3); System.out.print(d); } }
java 运算符
最新推荐文章于 2023-11-21 09:50:00 发布