Repository navigation
Expand file tree
/
Copy pathSyntaxStudy.java
More file actions
168 lines (144 loc) · 6.53 KB
/
Copy pathSyntaxStudy.java
File metadata and controls
168 lines (144 loc) · 6.53 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import org.junit.Test;
import java.lang.reflect.Array;
import java.util.Date;
import java.util.Locale;
import static org.junit.Assert.*;
/**
* Created by Administrator on 2016/9/28 0028.
*/
public class SyntaxStudy {
public String getString() {
return "Hello World!";
}
public char getChar() {
return 'A';
}
public void arrayTest() {
}
@Test
public void primitiveTypeTest() {
//region java string
System.out.println("java 字符串:");
System.out.printf("this is String Type:%s,getClass:%s \r\n", getString(), getString().getClass());
//endregion
System.out.println("java char :");
System.out.printf("this is char Type:%c \r\n", getChar());
System.out.println("java 4 种整型:");
System.out.printf("this is int Type:%d,4字节 \r\n", 4);
System.out.printf("this is short Type:%d,2字节 \r\n", 2);
System.out.printf("this is long Type:%d,8字节 \r\n", 8);
System.out.printf("this is byte Type:%d,1字节 \r\n", 1);
System.out.println("java boolean:");
boolean b = true;
System.out.printf("this is boolean Type:%b, \r\n", b, b);
}
@Test
public void stringTest() {
String str = null;
str = String.format("Hi,%s", "王力");
System.out.println(str);
str = String.format("Hi,%s:%s.%s", "王南", "王力", "王张");
System.out.println(str);
System.out.printf("字母a的大写是:%c %n", 'A');
System.out.printf("3>7的结果是:%b %n", 3 > 7);
System.out.printf("100的一半是:%d %n", 100 / 2);
System.out.printf("100的16进制数是:%x %n", 100);
System.out.printf("100的8进制数是:%o %n", 100);
System.out.printf("50元的书打8.5折扣是:%f 元%n", 50 * 0.85);
System.out.printf("上面价格的16进制数是:%a %n", 50 * 0.85);
System.out.printf("上面价格的指数表示:%e %n", 50 * 0.85);
System.out.printf("上面价格的指数和浮点数结果的长度较短的是:%g %n", 50 * 0.85);
System.out.printf("上面的折扣是%d%% %n", 85);
System.out.printf("字母A的散列码是:%h %n %n", 'A');
//$使用
str = String.format("格式参数$的使用:%1$d,%2$s", 99, "abc");
System.out.println(str);
//+使用
System.out.printf("显示正负数的符号:%+d与%d%n", 99, -99);
//补O使用
System.out.printf("最牛的编号是:%03d%n", 7);
//空格使用
System.out.printf("Tab键的效果是:% 8d%n", 7);
//.使用
System.out.printf("整数分组的效果是:%,d%n", 9989997);
//空格和小数点后面个数
System.out.printf("一本书的价格是:% 50.5f元%n%n", 49.8);
}
@Test
public void dateStringFormatTest() {
Date date = new Date();
//c的使用
System.out.printf("全部日期和时间信息:%tc%n", date);
//f的使用
System.out.printf("年-月-日格式:%tF%n", date);
//d的使用
System.out.printf("月/日/年格式:%tD%n", date);
//r的使用
System.out.printf("HH:MM:SS PM格式(12时制):%tr%n", date);
//t的使用
System.out.printf("HH:MM:SS格式(24时制):%tT%n", date);
//R的使用
System.out.printf("HH:MM格式(24时制):%tR %n%n", date);
//b的使用,月份简称
String str = String.format(Locale.US, "英文月份简称:%tb", date);
System.out.println(str);
System.out.printf("本地月份简称:%tb%n", date);
//B的使用,月份全称
str = String.format(Locale.US, "英文月份全称:%tB", date);
System.out.println(str);
System.out.printf("本地月份全称:%tB%n", date);
//a的使用,星期简称
str = String.format(Locale.US, "英文星期的简称:%ta", date);
System.out.println(str);
//A的使用,星期全称
System.out.printf("本地星期的简称:%tA%n", date);
//C的使用,年前两位
System.out.printf("年的前两位数字(不足两位前面补0):%tC%n", date);
//y的使用,年后两位
System.out.printf("年的后两位数字(不足两位前面补0):%ty%n", date);
//j的使用,一年的天数
System.out.printf("一年中的天数(即年的第几天):%tj%n", date);
//m的使用,月份
System.out.printf("两位数字的月份(不足两位前面补0):%tm%n", date);
//d的使用,日(二位,不够补零)
System.out.printf("两位数字的日(不足两位前面补0):%td%n", date);
//e的使用,日(一位不补零)
System.out.printf("月份的日(前面不补0):%te %n%n", date);
//H的使用
System.out.printf("2位数字24时制的小时(不足2位前面补0):%tH%n", date);
//I的使用
System.out.printf("2位数字12时制的小时(不足2位前面补0):%tI%n", date);
//k的使用
System.out.printf("2位数字24时制的小时(前面不补0):%tk%n", date);
//l的使用
System.out.printf("2位数字12时制的小时(前面不补0):%tl%n", date);
//M的使用
System.out.printf("2位数字的分钟(不足2位前面补0):%tM%n", date);
//S的使用
System.out.printf("2位数字的秒(不足2位前面补0):%tS%n", date);
//L的使用
System.out.printf("3位数字的毫秒(不足3位前面补0):%tL%n", date);
//N的使用
System.out.printf("9位数字的毫秒数(不足9位前面补0):%tN%n", date);
//p的使用
str = String.format(Locale.US, "小写字母的上午或下午标记(英):%tp", date);
System.out.println(str);
System.out.printf("小写字母的上午或下午标记(中):%tp%n", date);
//z的使用
System.out.printf("相对于GMT的RFC822时区的偏移量:%tz%n", date);
//Z的使用
System.out.printf("时区缩写字符串:%tZ%n", date);
//s的使用
System.out.printf("1970-1-1 00:00:00 到现在所经过的秒数:%ts%n", date);
//Q的使用
System.out.printf("1970-1-1 00:00:00 到现在所经过的毫秒数:%tQ%n", date);
}
@Test
public void numTest(){
int a=1;
int b=a++;
System.out.printf("a:%d,b:%d %n%n",a,b);
int c=++b;
System.out.printf("b:%d,c:%d",b,c);
}
}