Repository navigation
Expand file tree
/
Copy pathBasicDataType.java
More file actions
137 lines (115 loc) · 4.91 KB
/
Copy pathBasicDataType.java
File metadata and controls
137 lines (115 loc) · 4.91 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.util;
/**
*
* Java basic data types(�蔭�唳蝐餃�) and operations
*
* Java霂剛�銝箸�銝?銝芸�蝵格�桃掩��靘�撖孵���鋆掩�?
*
* @author wayne.zeng
*
*/
public class BasicDataType {
public static void main(String[] args) {
BasicDataType dt = new BasicDataType();
// BasicDataType.printInnerDataType();
// dt.byteOperation();
int a = 32;
byte b = 1;
System.out.println(Integer.BYTES);
System.out.println(Integer.SIZE);
System.out.println(Integer.toBinaryString(a));
System.out.println(Byte.BYTES);
System.out.println(Byte.toString(b));
System.out.println(b + 1);
System.out.println(b<<1);
}
/**
* variable x = (expression) ? value if true : value if false
*/
public void tripleOper(){
int a = 3;
int b = (a > 0) ? 0 : 1;
//This one is false: (b == 0) ? System.out.println("a > 0"),System.out.println("a < 0");
}
//explain of byte operation
public void byteOperation(){
int a = -7;
int b = 5;
System.out.println("a = " + a + "; b = " + b + " ; a&b: " + (a&b) );
System.out.println("a|b: " + (a|b));
System.out.println("a^b: " + (a^b));
System.out.println("~b: " + ~b);
System.out.println("<<: �餉�撌衣宏嚗雿‘�塚�a<<2: " + (a<<2) );
System.out.println(">>: 撣衣泵�瑕蝘鳴�撌虫�銵亦泵�?-甇�銵?0嚗��啗‘1嚗>>2嚗?" + (a>>2));
System.out.println(">>>: �泵�瑕蝘鳴�撌虫�銵仿嚗>>>2: " + (a>>>2));
}
public void byteExample(){
int a = 60; /* 60 = 0011 1100 */
int b = 13; /* 13 = 0000 1101 */
int c = 0;
c = a & b; /* 12 = 0000 1100 */
System.out.println("a & b = " + c );
c = a | b; /* 61 = 0011 1101 */
System.out.println("a | b = " + c );
c = a ^ b; /* 49 = 0011 0001 */
System.out.println("a ^ b = " + c );
c = ~a; /*-61 = 1100 0011 */
System.out.println("~a = " + c );
c = a << 2; /* 240 = 1111 0000 */
System.out.println("a << 2 = " + c );
c = a >> 2; /* 15 = 1111 */
System.out.println("a >> 2 = " + c );
c = a >>> 2; /* 15 = 0000 1111 */
System.out.println("a >>> 2 = " + c );
}
/**
* java �其�餈銵亦��亥”蝷箏�摮�啣??
*/
public static void printInnerDataType() {
// byte
System.out.println("�箸蝐餃�嚗yte 鈭��嗡��堆�" + Byte.SIZE);
System.out.println("��蝐鳴�java.lang.Byte");
System.out.println("�?撠?潘�Byte.MIN_VALUE=" + Byte.MIN_VALUE);
System.out.println("�?憭批?潘�Byte.MAX_VALUE=" + Byte.MAX_VALUE);
System.out.println();
// short
System.out.println("�箸蝐餃�嚗hort 鈭��嗡��堆�" + Short.SIZE);
System.out.println("��蝐鳴�java.lang.Short");
System.out.println("�?撠?潘�Short.MIN_VALUE=" + Short.MIN_VALUE);
System.out.println("�?憭批?潘�Short.MAX_VALUE=" + Short.MAX_VALUE);
System.out.println();
// int
System.out.println("�箸蝐餃�嚗nt 鈭��嗡��堆�" + Integer.SIZE);
System.out.println("��蝐鳴�java.lang.Integer");
System.out.println("�?撠?潘�Integer.MIN_VALUE=" + Integer.MIN_VALUE);
System.out.println("�?憭批?潘�Integer.MAX_VALUE=" + Integer.MAX_VALUE);
System.out.println();
// long
System.out.println("�箸蝐餃�嚗ong 鈭��嗡��堆�" + Long.SIZE);
System.out.println("��蝐鳴�java.lang.Long");
System.out.println("�?撠?潘�Long.MIN_VALUE=" + Long.MIN_VALUE);
System.out.println("�?憭批?潘�Long.MAX_VALUE=" + Long.MAX_VALUE);
System.out.println();
// float
System.out.println("�箸蝐餃�嚗loat 鈭��嗡��堆�" + Float.SIZE);
System.out.println("��蝐鳴�java.lang.Float");
System.out.println("�?撠?潘�Float.MIN_VALUE=" + Float.MIN_VALUE);
System.out.println("�?憭批?潘�Float.MAX_VALUE=" + Float.MAX_VALUE);
System.out.println();
// double
System.out.println("�箸蝐餃�嚗ouble 鈭��嗡��堆�" + Double.SIZE);
System.out.println("��蝐鳴�java.lang.Double");
System.out.println("�?撠?潘�Double.MIN_VALUE=" + Double.MIN_VALUE);
System.out.println("�?憭批?潘�Double.MAX_VALUE=" + Double.MAX_VALUE);
System.out.println();
// char
System.out.println("�箸蝐餃�嚗har 鈭��嗡��堆�" + Character.SIZE);
System.out.println("��蝐鳴�java.lang.Character");
// 隞交�澆耦撘?��臬�蝚血耦撘�Character.MIN_VALUE颲�唳�嗅
System.out.println("�?撠?潘�Character.MIN_VALUE="
+ (int) Character.MIN_VALUE);
// 隞交�澆耦撘?��臬�蝚血耦撘�Character.MAX_VALUE颲�唳�嗅
System.out.println("�?憭批?潘�Character.MAX_VALUE="
+ (int) Character.MAX_VALUE);
}
}