强制转换

东林梁

关注

阅读 55

2023-03-25

public class TestDemo {
    public static void main(String[] args) {
        double a=13.4;
        int b=(int)a;
        System.out.println(b);
        //运行结果为int b=13,  0.4丢失
        int c=12;
        byte d=(byte) c;
        System.out.println(d);
        //运行结果为byte d=12;
        int sum1=130;
        byte sum2=(byte) sum1;
        System.out.println(sum2);
        //运行结果为byte sum2=-126;
    }
}

精彩评论(0)

0 0 举报