package operator; //逻辑运算符 && (与)、||(或)、!(非) public class Demo05 { public static void main(String[] args) { 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);//false System.out.println(c);//5 } }
package operator; public class Demo06 { public static void main(String[] args) { System.out.println(); /* A = 0011 1100 B = 0000 1101 A&B 0000 1100 A/B 0011 1101 A^B 0011 0001 相同取0,不同得1 ~A 1100 0011 取反 2*8 怎么运算最快? << *2 >> /2 */ System.out.println(2<<3); } }
package operator; public class Demo07 { public static void main(String[] args) { int a = 10; int b = 20; a+=b; //a=a+b a-=b; //a=a-b System.out.println(a);//10 //字符串连接符 + System.out.println(a+b); //30 System.out.println(""+a+b); //1020 只要不在最末尾,都会把其余转化为String System.out.println(a+b+""); //30 } }
package operator; //三元运算符 public class Demo8 { public static void main(String[] args) { // x?y:z //x ture 结果为y,否则结果为z int score = 80; String type = score < 60 ?"不及格":"及格"; //必须掌握 System.out.println(type); } }