Java 三目运算符

 1 public class Test {
 2     public static void main(String args[]){
 3         int a , b;
 4         a = 10;
 5 
 6         b = (a == 1) ? 20 : 30;
 7         // 如果a等于1那么b就等于20,否则等于30
 8 
 9         System.out.println( "Value of b is : " + b );
10         b = (a == 10) ? 20 : 30;
11         System.out.println( "Value of b is : " + b );
12 
13     }
14 }
15 
16 输出:
17 Value of b is : 30
18 Value of b is : 20

猜你喜欢

转载自www.cnblogs.com/liyihua/p/11668389.html