GitOPEN's Home.

《Monkey Java》课程2.x之巩固练习

Word count: 290 / Reading time: 1 min
2015/07/03 Share

练习:(请动手)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* 注意:类名一定和java源文件的名称一致。即 Demo。
*
* @author Monkey
*
*/
public class Demo {
public static void main(String[] args) {
// 布尔型
boolean b = false;
boolean bb = true;
System.out.println("b-->" + b + ",bb-->" + bb);

// 字符型
char c = 'a';
char cc = '猴';
System.out.println("c-->" + c);
System.out.println("cc-->" + cc);

/**
* 1.整数字面量为整型int 2.小数字面量为双精度浮点型double
*/
// 数值型
byte b01 = 0;
short s = 0;
int i = 0;

long l = 0;
long ll = 1;

float f = 0;
float ff = 0.1f; // 注意写0.1就会报错(可能损失精度)

double d = 0;

System.out.println("b01-->" + b01);
System.out.println("s-->" + s);
System.out.println("i-->" + i);
System.out.println("l-->" + l);
System.out.println("ll-->" + ll);
System.out.println("f-->" + f);
System.out.println("ff-->" + ff);
System.out.println("d-->" + d);

/**
* 数值型表数范围的关系: byte < short < int < long < float < double
*
* 大范围类型的的变量和小范围类型的变量相互操作,就会产生“可能损失精度”的错误;
*
* 例如: int temp01 = 10; long temp02 = 100; temp01 = temp02;
*/
}
}

欣慰帮到你 一杯热咖啡
【奋斗的Coder!】企鹅群
【奋斗的Coder】公众号
CATALOG
  1. 1. 练习:(请动手)