天天看點

java-int&short-byte類型轉換問題

public class Demo {
    public static void main(String[] args) {
        byte a=,b=,c;

        c=(byte) (a+b);     //變量會自動提升為int  是以丢失精度 會報錯       

        c=+;      //如果數值是常量  他會根據計算是否超過c的存儲範圍,超過才報錯;

        short a1=,b1=,c1;

        c1=(short) (a1+b1);     //變量會自動提升為int  是以丢失精度 會報錯   
        c1=+;         //如果數值是常量  他會根據計算是否超過c的存儲範圍,超過才報錯;

        long a2=,b2=,c2;


        float a3=f,b3=f,c3;       

        c3=a3+b3;

        System.out.println("hello"+'a'+);      //從左到右操作  字元串與任何資料相加都是直接拼接  helloa1
        System.out.println('a'++"hello");      //從左到右操作  'a'=97+1=98 再拼接hello      98hello


    }
}