Java 三目运算符
直接实例理解
public class Test {
public static void main(String args[]){
int a , b;
a = 10;
b = (a == 1) ? 20 : 30;
// 如果a等于1那么b就等于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
本文来自博客园,作者:LeeHua,转载请注明原文链接:https://www.cnblogs.com/liyihua/p/11668389.html