条件运算符也称为三元运算符。此运算符包含三个操作数,用于评估布尔表达式。运算符的目标是决定应为变量分配哪个值。运算符的写法如下:变量 x = (表达式)?如果为真则为值:如果为假则为值示例public class Test { public static void main(String args[]) { int a, b; a = 10; b = (a == 1) ? 20: 30; System.out.println("Value of b is: " + b); b = (a == 10) ? 20: 30; System.out.println(“Value of b is: " + b); } }输出Value of b is: 30 Value of b is: 20