关于三元运算符

直接贴代码吧!记录一下

public static void main(String[] args) 
{
        
        int num = 4;
        System.out.println((num > 4) ? 99.0 : 9);//9.0
        
        char a = 'a';
        int i = 96;
        
        System.out.println(2==2?i:9.0); //96.0
        System.out.println(2==2?98:a); //b
        
        System.out.println(2==2?a:i); //
        
        System.out.println(2==2?99:9.0); //99.0
        
        System.out.println(2==2 ? 99 : 'b' ); //c
}

解决方案:http://www.mamicode.com/info-detail-1010428.html

 

posted @ 2016-11-08 19:33  heyLuer  阅读(159)  评论(0编辑  收藏  举报