java运算符
面试题1: 计算2*8如何操作效率更高?
剖析: 2 * 8 => 实际上是2 * 2 * 2 * 2
2<<3
System.out.println(2<<3);
面试题2: ""+a+b 和 a+b+""的输出结果
Integer a = 10;
Integer b = 20;
System.out.println(a+b+""); // 结果为30
System.out.println(""+a+b); // 结果为1020
/*
代码简洁
*/
a +=b; // a = a + b;
System.out.println(a);
a -=b; // a = a - b;
// 同理还有a *= b => a = a * b;
System.out.println(a);
三元运算符 x ? y : z
解释:如果x == true,则结果为y,否则结果为z
double score = 70.5;
String type = score < 60? "不及格":"及格";
System.out.println(type);
标签:学习,面试题,java,System,运算符,println,out
From: https://www.cnblogs.com/sihai9105/p/16970033.html