Java基本数据类型学习记录

Java基本数据类型

整形

  1. byte

    byte占用一个字节,-128~127

  2. short

    short占用2个字节,-36728~36726

  3. int

    int占用4个字节,范围很大21亿多

  4. long

    long占用8个字节,范围更大

浮点型

  1. float

    float占用4个字节

  2. double

    double占用8个字节

字符类型

字符类型就一个char,占用2个字节,这里要切记String不是基本类型,很多人初学者会以为String是基本类型里面的字符类型。

Boolean

boolean占用一位字节,它的值只有false,true

idea代码演示

public class text {
    public static void main(String[] args) { //psvm是主方法的快捷键
        byte a=1;
        short b=2;    //byte和short注意不要超过它们的范围了
        int c=3;
        long d=4L;   //使用long是,需要在数据后面跟一个大写的L
        float s=1.111F ;  /*使用float时,数据后面也要跟一个大写的F
                          不过我们一般都是使用double*/
        double r=3.1415926535;
        char tt='q';
        //Boolean flag=true;
        //Boolena flag1=false;
        System.out.println(a); //sout是输出的快捷键
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
        System.out.println(s);
        System.out.println(r);
        System.out.println(tt);
​
​
    }
}
​

Guess you like

Origin blog.csdn.net/qq_47499256/article/details/121051821