数据类型

数据类型

基本类型(primitive type)

  1. 数值类型

    • 整数类型

      • byte占1字节范围:-128~127

      • short占2个字节范围:-32768~32767

      • int占4个字节范围:-2147483648~2147483647

      • long占8个字节范围:-9223372036854775808~9223372036854775807

      • 整数扩展

        public class Demo03 {
            public static void main(String[] args){
                //整数拓展:   进制    二进制0b    十进制    八进制0   十六进制0x
                int i = 10;
                int i2 = 010;  //八进制0
                int i3 = 0X10; //十六进制0x    0~9 A~F
        
                System.out.println(i);
                System.out.println(i2);
                System.out.println(i3);
            }
        }

    • 浮点类型

      • float占4个字节

      • double占8个字节

      • 浮点扩展

        public class Demo03 {
            public static void main(String[] args){
                //浮点数拓展    
                //float
                //double
        
                float f = 0.1f; //0.1
                double e = 1.0/10; //0.1
                System.out.println(f);
                System.out.println(e);
                System.out.println(f==e); //false  (不一样)
        
                //float   有限的   离散的   舍入误差   大约   接近但不等于
        
                float x1 = 123456789f;
                float x2 = x1 + 1;
                System.out.println(x1 == x2); //true  (一样)
                //最好避免使用浮点数进行比较!
                //最好避免使用浮点数进行比较!
                //最好避免使用浮点数进行比较!
            }
        }

    • 字符类型

      • char占2个字节

      • 字符扩展

        public class Demo03 {
            public static void main(String[] args) { 
                //字符拓展
        
                char a1 = 'a';
                char a2 = '瑭';
              
                System.out.println(a1);
                System.out.println((int)a1); //强制转换
        
                System.out.println(a2);
                System.out.println((int)a2); //强制转换
        
                //所有的字符本质还是数字
                //编码 Unicode 表:(a = 97  瑭 = 29825)  2字节  0 - 65536
                //注:所有的字符本质还是数字,编码Unicode表可以转译字符
                //U0000 UFFFF
        
                char a3 = '\u0061';
        
                System.out.println(a3); //a
            }
        }
        
        
        ​
        ​
  2. boolean类型:占1位其值只有true和false两个

引用类型(reference type)

  1. 接口

  2. 数组

转义符扩展

public class Demo03 {
    public static void main(String[] args) {
        //转义字符
        // \t  制表符
        // \n  换行

        System.out.println("中\t国");
        System.out.println("中\n国");
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值