Java基础知识

八种基本数据类型

整数类型

  1. byte 占一个字节
  2. short 占两个字节
  3. int 占四个字节
  4. long 占八个字节

浮点数类型

  1. float 占四个字节
  2. double 占八个字节

字符类型

  1. char 占两个字节(在c语言中占一个字节)

    可能有的人认为string也是字符类型,但其实string不是基本数据类型,String是一个对象

布尔类型

  1. boolean 占一个字节(true或者false)
package Test1;

public class BianDeom {

    /*
            注意定义long类型变量的时候要加上L或l
            注意定义float类型变量的时候要加上F或f
     */
    public static void main(String[] args) {
        //定义byte类型
        byte b = 10;
        System.out.print(b);
        System.out.print("\r");

        //定义short类型
        short s = 9;
        System.out.print(s);
        System.out.print("\r");

        //定义int类型
        int i = 8;
        System.out.println(i);

        //定义long类型
        long l =10000L;
        System.out.println(l);

        //定义float类型
        float f = 3.14F;
        System.out.println(f);

        //定义double类型
        double d = 3.14;
        System.out.println(d);

        //定义char类型
        char c = 'a';
        System.out.println(c);

        //定义boolean类型
        boolean bl = true;
        System.out.println(bl);

    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值