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
posted @ 2019-10-13 21:13  LeeHua  阅读(650)  评论(0编辑  收藏  举报