数据类型扩展

Demo2

public class Demo2 {
  public static void main(String[] args) {
      int a=10;
      //10进制-10
      int b=010;
      //8进制-8
      int c=0x10;
      //16进制-16
      System.out.println(a);
      System.out.println(b);
      System.out.println(c);
      System.out.println("==========");
      float aa=0.1f;
      double bb=1/10;
      System.out.println(aa==bb);
      //false
      System.out.println("==========");
      char c1='a';
      char c2='中';
      System.out.println(c1);
      System.out.println(c2);
      System.out.println((int)c2);
      //20013强制转换
      char c3='\u0061';
      System.out.println(c3);
      //a
  }
}

类型转换

  1. 不能对布尔值进行转换

  2. 不能把对象类型转换为不相干的类型

  3. 高容量转换为低容量时,强制转换

  4. 转换的时候可能存在溢出,或者精度问题

数字之间可以用下滑线分割

int a=1_0000;

 

posted @ 2021-10-05 21:37  clown-lan  阅读(26)  评论(0)    收藏  举报