Java 基本数据类型

public class SumType {
    public static void main(String[] args) {
        /**
         *  布尔类型
         *  1 字节
         */
        boolean bool = false;// 默认
        boolean bool2 = true;
        System.out.println("bool = " + bool);
        System.out.println("bool2 = " + bool2);
        System.out.println("----------------------------------");
        /**
         *  byte类型
         *  1 字节
         *  范围 [-128 0 127]   (2^7 0 2^7-1)
         */
        byte b1 = -128;
        byte b0= 0;// 默认
        byte b2 =127;
        System.out.println("b0 = " + b0);
        System.out.println("b1 = " + b1);
        System.out.println("b2 = " + b2);
        System.out.println("----------------------------------");
        /**
         *  字符类型
         *  2 字节
         *  范围 [\u0000 \uffff] (0 65535) 2^16 (无符号整数)
         */
        char ch =97;
        char ch1 = 'a';
        System.out.println("ch = " + ch);
        System.out.println("ch1 = " + ch1);
        System.out.println("----------------------------------");
        /**
         *  短整数类型
         *  2 字节
         *  范围[-32768 32767] (-2^15 2^15-1)
         */
        short s1 = -32768;
        short s0 = 0;// 默认
        short s3 = 32767;
        System.out.println("s1 = " + s1);
        System.out.println("s0 = " + s0);
        System.out.println("s3 = " + s3);
        System.out.println("----------------------------------");
        /**
         *  整数类型
         *  4 字节
         *   范围 正负 21 亿左右 (-2^31 2^31-1)
         */
        int i1 = -2147483648 ;
        int i0 = 0;// 默认
        int i2 = 2147483647;
        System.out.println("i0 = " + i0);
        System.out.println("i1 = " + i1);
        System.out.println("i2 = " + i2);
        System.out.println("----------------------------------");
        /**
         *  长整数类型
         *  8 字节
         *  范围 (-2^63  2^63)
         */
        long l1 = -9223372036854775808L;
        long l0 = 0L;// 默认
        long l2 = 9223372036854775807L;
        System.out.println("l0 = " + l0);
        System.out.println("l1 = " + l1);
        System.out.println("l2 = " + l2);
        System.out.println("----------------------------------");

        /**
         *  单精度浮点类型
         *  4 字节
         * -3.4E+38 ~ 3.4E+38 之间
         *  有效数字 6-7
         */
        float f = 0.0f;// 默认
        System.out.println("f = " + f);
        System.out.println("----------------------------------");
        /**
         *  双精度浮点类型
         *  8 字节
         *  有效数字15-16
         */
        double d = 0.0;// 默认
        System.out.println("d = " + d);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值