JavaSe 三元运算符 的 一个小特性

import java.time.Instant;

public class s1 {

    private static Double Double;
    //三元运算法的特点  是个吃亏题...
    public static void main(String[] args) {
        int x = 4;
        //三元运算符 和他比的是 double  因为double 精度大 默认转 double
        System.out.println(" is " + ((x > 4)? 99.9 : 9) );
        System.out.println(" is " + ((x == 4)? 99 : 99.9) );


        //三元运算符 和他比的是 int  所以 转int
        System.out.println(" is " + ((x > 4)? 99 : 9) );
        System.out.println(" is " + ((x == 4)? 9 : 99) );
    }
}

无意中看到  谨记即可.

本文来自博客园,作者:咸瑜,转载请注明原文链接:https://www.cnblogs.com/bi-hu/p/14960606.html

原文地址:https://www.cnblogs.com/bi-hu/p/14960606.html