zoukankan      html  css  js  c++  java
  • Java之数据类型讲解

    Java数据类型关系图

     

    基本数据类型

     从小到大的关系图:

     

     

    图中从左向右的转换都是隐式转换,无需再代码中进行强制转换 :

    byte i = 12;
    System.out.println("byte:"+i);
    short i2 = i;
    System.out.println("short:"+i2);
    int i3 = i;
    System.out.println("int:"+i3);
    long i4 = i;
    System.out.println("long:"+i4);
    float i5 = i;
    System.out.println("float:"+i5);
    double i6 = i;
    System.out.println("double:"+i6);
     
     
    char j = '²';
    System.out.println("char:"+j);
    int j3 = j;
    System.out.println("int:"+j3);
    long j4 = j;
    System.out.println("long:"+j4);
    float j5 = j;
    System.out.println("float:"+j5);
    double j6 = j;
    System.out.println("double:"+j6);

    运行结果:

    byte:12
    short:12
    int:12
    long:12
    float:12.0
    double:12.0
    charint:178
    long:178
    float:178.0
    double:178.0

    从右向左均要进行强制类型转换,才能通过编译。强制转换会丢失精度。这里省略代码。

    引用数据类型

     String是引用数据类型

  • 相关阅读:
    android ndk 调试问题
    音频
    文件分割与c语言文件结
    本机抓包
    rtm匹 转
    mac 工具等效率
    【MySQL】Explain Tutorial
    Sed基本入门[5] Sed Hold and Pattern Space Commands
    Sed基本入门[3] Regular Expressions
    Protocol Buffer Basics
  • 原文地址:https://www.cnblogs.com/htyj/p/11699304.html
Copyright © 2011-2022 走看看