Ternary operator rules
布尔表达式?表达式1:表达式2
Operation process: If the value of the Boolean expression is true, return the value of expression 1, otherwise return the value of expression 2
例如:
int x = 100;
int y = 50;
int z;
如果x大于y 则是true,将x赋值给z;
如果x不大于y 则是false,将y赋值给z;
z = (x > y) ? x : y;
When encountering multiple data judgments, the goal can be achieved through the nesting of ternary operations
state == 0 ? "未用" : (state == 1 ? "在用" : "停用")