zoukankan      html  css  js  c++  java
  • Java基础知识(二)基本数据类型转换

    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;
    
        }
    }
  • 相关阅读:
    DHCP协议详解(硬件方面原理)
    ASP.NET安全认证
    JAVA打包成.jar可运行项目
    JAVA菜单事件
    JAVA事件概述
    JAVA对话框事件
    各种事件汇聚
    把原来可空的列变成主键
    搜索模式中的所有表
    JAVA选项事件
  • 原文地址:https://www.cnblogs.com/liw66/p/11576449.html
Copyright © 2011-2022 走看看