171106

一些容易忽略的细节问题

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class {
public static void main(String... args) throws UnsupportedEncodingException {
System.out.println("Math.round(11.5) is " + Math.round(11.5));
System.out.println("Math.round(-11.5) is " + Math.round(-11.5));
// floor 向下取整
System.out.println("Math.floor(11.5) is " + Math.floor(11.5));
System.out.println("Math.floor(-11.5) is " + Math.floor(-11.5));
// ceil 向下取整
System.out.println("Math.ceil(11.5) is " + Math.ceil(11.5));
System.out.println("Math.ceil(-11.5) is " + Math.ceil(-11.5));
// 字符数组的输出格式
char[] a = {'a', 'b', 'c'};
System.out.println(a);
// 字符串列表的输出格式
List<String> ls = new ArrayList();
ls.add("a");
ls.add("b");
ls.add("c");
System.out.println(ls);
// 字符列表的输出格式
List<Character> lc = new ArrayList();
lc.add('a');
lc.add('b');
lc.add('c');
System.out.println(lc);
// 取模运算的符号和小数点
System.out.println("100 % 3 is " + (100 % 3));
System.out.println("100 % 3.0 is " + (100 % 3.0));
System.out.println("100 % -3 is " + (100 % -3));
System.out.println("100 % -3.0 is " + (100 % -3.0));
System.out.println("-100 % -3 is " + (-100 % -3));
System.out.println("-100 % -3.0 is " + (-100 % -3.0));
System.out.println("-100 % 3 is " + (-100 % 3));
System.out.println("-100 % 3.0 is " + (-100 % 3.0));
Random random = new Random();
boolean isE = true;
for (int i = 0; i < 1000; i++) {
int v = random.nextInt();
if (v == 0)
v += 1;
if (10000 % v != 10000 % (-v) && 10000 % v >= 0) {
isE = false;
break;
}
if (-10000 % v != -10000 % (-v) && 10000 % v <= 0) {
isE = false;
break;
}
}
System.out.println(" x % y answer is " + isE);
// Unicode 只是表示了符号的二进制代码,并没有说怎么存储
// 而 utf-8 等表示了如何存储 unicode 的二进制代码
System.out.println("中国abc".getBytes("Unicode").length);
System.out.println("中国abc".getBytes("UTF-8").length);
}
}
class Parent {
String name = "Jack";
private Parent(){
this.name = "Rose";
}
public String getName() {
return name;
}
}
//error
//class Child extends Parent {
//
//}

####$$ output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Math.round(11.5) is 12
Math.round(-11.5) is -11
Math.floor(11.5) is 11.0
Math.floor(-11.5) is -12.0
Math.ceil(11.5) is 12.0
Math.ceil(-11.5) is -11.0
abc
[a, b, c]
[a, b, c]
100 % 3 is 1
100 % 3.0 is 1.0
100 % -3 is 1
100 % -3.0 is 1.0
-100 % -3 is -1
-100 % -3.0 is -1.0
-100 % 3 is -1
-100 % 3.0 is -1.0
x % y answer is true
12
9