什么是条件运算符?:在Java中?
条件运算符也称为三元运算符。该运算符由三个操作数组成,用于评估布尔表达式。操作者的目标是决定;应将哪个值分配给变量。运算符写为:
variable x = (expression)? value if true: value if false
示例
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
热门推荐
10 聚餐朋友喝酒祝福语简短
11 回国了祝福语简短英语
12 出嫁条幅伴娘祝福语简短
13 婆婆高寿祝福语大全简短
14 上嫂子生日祝福语简短
15 宝子生日祝福语简短
16 男朋友新年祝福语简短
17 孙女结婚姥姥祝福语简短
18 学生宴祝福语简短的