首页 > 编程语言 > 详细

Java基础知识(二)基本数据类型转换

时间:2019-09-24 10:46:28      阅读:96      评论:0      收藏:0      [点我收藏+]
public class test_20190923 {

    public static void main(String... as) {
        // 基本类型转换 低精度到高精度隐式转换 高精度到低精度显式转换
        // 1.byte to any
        byte b = 1;
        short s = b;
        int i = b;
        long l = b;
        float f = b;
        double d = b;

        // 2.short to any
        short s2 = 1;
        byte b2 = (byte) s2;
        int i2 = s2;
        long l2 = s2;
        float f2 = s2;
        double d2 = s2;

        // 3.int to any
        int i3 = 1;
        byte b3 = (byte) i3;
        short s3 = (short) i3;
        long l3 = i3;
        float f3 = i3;
        double d3 = i3;

        // 4.long to any
        long l4 = 1l;
        byte b4 = (byte) l4;
        short s4 = (short) l4;
        int i4 = (int) l4;
        float f4 = l4;
        double d4 = l4;

        // 5.float to any
        float f5 = 1.0f;
        byte b5 = (byte) f5;
        short s5 = (short) f5;
        int i5 = (int) f5;
        long l5 = (long) f5;
        double d5 = f5;

        // 6.double to any
        double d6 = 1.00d;
        byte b6 = (byte) d6;
        short s6 = (short) d6;
        int i6 = (int) d6;
        long l6 = (long) d6;
        float f6 = (float) d6;

        // 7.char to any
        char c7 = ‘a‘;
        byte b7 = (byte) c7;
        short s7 = (short) c7;
        int i7 = c7;
        long l7 = c7;
        float f7 = c7;
        double d7 = c7;

    }
}

 

Java基础知识(二)基本数据类型转换

原文:https://www.cnblogs.com/liw66/p/11576449.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!