基本数据类型(primitive type)

发布时间 2023-07-01 10:26:24作者: Kazuma_124

数据类型

数据类型分为基本数据类型(primitive type)和引用数据类型(reference type)

  • 基本数据类型(primitive type)
    • 数值类型
      • 整数类型
      • 浮点类型
      • 字符类型
    • boolean类型
  • 引用数据类型(reference type)
    • 接口
    • 数组

八大基本数据类型

  • byte,占1个字节(1B),表示整数范围:-128--127
  • short,占2个字节(2B),表示整数范围:-32768--32767
  • int,占4个字节(4B),表示整数范围:-2147483648--2147483647
  • long,占8个字节(8B),表示整数范围:-9223372036854775808--9223372036854775807
  • float,占4个字节(4B),表示小数
  • double,占8个字节(8B),表示小数
  • char,占两个字节(2B),表示单个字符
  • boolean,占1位(1bit)

代码

byte bytemax = 127;
short shortmax = 32767;
int intmax = 2147483647;
long longmax = 9223372036854775807L;//long比较特殊,其描述的变量的值后要加“L”
float decimal1 = 3.1415928F;//float描述的变量的值后要加“F”
double decimal2 =3.14155928535;
char letter = a;
boolean flag = true;//true or false
System.out.println(bytemax+","+shortmax+","+intmax+","+longmax+","+decimal1+","+decimal2+","+letter+","+flag);