数据类型

来源:互联网 发布:天下三女鬼墨捏脸数据 编辑:程序博客网 时间:2024/05/16 05:29

数据类型

java标识符:各变量、方法和类等要素命名时使用的字符序列;
java字符要“见名知意”,不可与关键字重名。

程序执行过程
程序执行过程

java变量分类:局部变量和成员变量。
java面向对象,所以变量必须在class内。

TestVar

public class TestVar {    static int j;    public void m() {        int i = 2;        System.out.println(i);     }     //为什么不执行?    public static void main(String[] args) {        int i =3;         System.out.println(i);        System.out.println(j);        boolean b = false;        if(b) {            int c = 0;            System.out.println("b is true");        }        //System.out.println(c);        long longNum1 = 8888888888L;    }}

数据类型:
1. 布尔 boolean(只允许取值true或false)
2. 字符 char(采用‘unicode’2字节)
3. 整数 byte int short long (1 2 4 8字节,字节数固定且不受操作系统影响。)。默认是int类型,声明long类型需加’l’或‘L’
4. 浮点数 float double 。默认是double类型,声明float类型需加’f’或‘F‘。浮点数有一定的误差。

TestVar2

public class TestVar2 {    public static void main(String[] args) {            boolean b = true;      int x, y = 9;      double d = 3.1415;      char c1, c2;      c1 = '\u534e';        c2 = 'c';      x = 12;      System.out.println("b=" +b);      System.out.println   ("x=" + x +",y=" + y);               System.out.println("d=" + d);      System.out.println("c1=" + c1);      System.out.println("c2=" + c2);    }}
0 0
原创粉丝点击