java四类八种

四类

八种

字节数

数据表示范围

byte

1

-128~127

short

2

-32768~32767

int

4

-2147483648~2147483648

long

8

-263~263-1

浮点型

float

4

-3.403E38~3.403E38

double

8

-1.798E308~1.798E308

字符型

char

2

表示一个字符,如('a','A','0','家')

布尔型

boolean

1

只有两个值true与false

 1 package day01;
 2 
 3 /**
 4  * @author mayi
 5  * @date 2018年5月1日 下午4:30:13
 6  * 
 7  * @project_name javaStudy
 8  * @package_name day01
 9  * @file_name Variabe.java
10  * @description 
11  */
12 public class Variabe {
13 //        定义Java中的变量
14 //       定义出所有数据类型的变量
15 //       四类八种
16         public static void main (String[] args) {
17                 //定义整数类型,字节类型 byte类型
18                 //内存中1个字节, -128 127
19                 byte b = 100;
20                 System.out.println(b);
21                 
22                 //定义整数类型,短整型, short类型
23                 //内存中2个字节, -32768 32767
24                 short s = 200;
25                 System.out.println(s);
26                 
27                 //定义整数类型, 整型, int类型
28                 //内存中4个字节, -2147483648  2147483647
29                 int i = 500006;
30                 System.out.println(i);
31                 
32                 //定义整数类型, 长整型, long类型
33                 //内存中8个字节
34                 long l = 21474836407L;
35                 System.out.println(l);
36                 
37                 //定义浮点数据, 单精度 float类型
38                 //内存中4个字节
39                 float f = 1.0F;
40                 System.out.println(f);
41                 
42                 
43                 //定义浮点数据, 双精度 double类型
44                 //内存中8个字节
45                 double d = 2.2;
46                 System.out.println(d);
47                 
48                 //定义字符类型, char
49                 //内存中2个字节, 必须单引号包裹,只能写1个字符
50                 char c = 'm';
51                 System.out.println(c);
52                 
53                 //定义布尔类型, boolean
54                 //内存中1个字节, 数据值, true false
55                 boolean bool = true;
56                 System.out.println(bool);
57         }
58 }

猜你喜欢

转载自www.cnblogs.com/webwrangler/p/8976639.html