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
|
package
com.jikexueyuan.ch01;
import
java.util.*;
import
java.io.Console;
import
java.io.PrintStream;
import
java.text.SimpleDateFormat;
import
java.math.BigInteger;
public
class
test01{
/* public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");//设置日期格式
int f = 9-(df.format(new Date()));
System.out.println(f);
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
}
} */
public static void main(String[] args) throws Exception {
//public static String reduceStr(String augend, String augend2) {
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
//System.out.println(sdf.format(new Date()));
String str = (sdf.format(new Date()));
char[] dist = new char[str.length()];
for(int x = str.length() - 1, p = 0; x >= 0; x--){
dist[p++] = str.charAt(x);
}
BigInteger aa =new BigInteger("99999999");
BigInteger bb= new BigInteger(new String(dist));
BigInteger sub=aa.subtract(bb);
System.out.println(sub.toString());
/* String string=sub.toString();
string=string.replace("0","c02");
string=string.replace("1","x03");
string=string.replace("2","f04");
string=string.replace("3","a05");
string=string.replace("4","b06");
string=string.replace("5","e07");
string=string.replace("6","g08");
string=string.replace("7","k09");
string=string.replace("8","s10");
string=string.replace("9","t11");
System.out.println(string); */
//数字转换字符串
String s = sub.toString();
char
[] charArray = s.toCharArray();
String[] strings =
new
String[charArray.length];
for
(
int
k =
0
; k < charArray.length; k++) {
String c = String.valueOf(charArray[k]);
int
parseInt = Integer.parseInt(c);
if
(parseInt ==
0
) {
strings[k] =
"c02"
;
// 这里自己替换
}
else
if
(parseInt ==
1
) {
strings[k] =
"x03"
;
}
else
if
(parseInt ==
2
) {
strings[k] =
"f04"
;
}
else
if
(parseInt ==
3
) {
strings[k] =
"a05"
;
}
else
if
(parseInt ==
4
) {
strings[k] =
"b06"
;
}
else
if
(parseInt ==
5
) {
strings[k] =
"e07"
;
}
else
if
(parseInt ==
6
) {
strings[k] =
"g08"
;
}
else
if
(parseInt ==
7
) {
strings[k] =
"k09"
;
}
else
if
(parseInt ==
8
) {
strings[k] =
"s10"
;
}
else
if
(parseInt ==
9
) {
strings[k] =
"t11"
;
}
else
{
strings[k] = c;
}
}
StringBuffer sb =
new
StringBuffer();
for
(
int
k =
0
; k < strings.length; k++) {
sb.append(strings[k]);
}
String result = sb.toString();
System.out.println(result);
}
}
|
本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/1632911