1. 程式人生 > >Java語言基礎long與float的取值範圍誰大誰小

Java語言基礎long與float的取值範圍誰大誰小

結論

float的取值範圍比long大

驗證

public class Test1_DataTypeConversion {

    public static void main(String[] args) {

        float f = 1.3f;
        long l = 34;
//        l = f;
//        System.out.println(l);
        //Type mismatch: cannot convert from float to long
        f = l;
        System.out.println(f);


    }

}

進行混合運算的時候 byte short char 不會相互轉換 都會自動提升為int

取值範圍大小如下

char < int < long < float