三元运算符
注意:字符串在+之前,则+后面的都为字符串;字符串在+之后,前面的依旧会运算
package operator;
public class DemoSix {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println(a+b);//30
//字符串连接 + String
//字符串在+之前,则+后面的都为字符串;字符串在+之后,前面的依旧会运算
System.out.println(""+a+b);//字符串:1020
System.out.println(a+b+"");//30
//三元运算符 x ? y : z
//如果x为true,则结果为y;否则结果为z
int score = 80;
String type = score<60 ? "fail" : "pass";
System.out.println(type); //pass
}
}