-
Notifications
You must be signed in to change notification settings - Fork 0
/
lanqiao 报时助手
116 lines (85 loc) · 2.54 KB
/
lanqiao 报时助手
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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int h = in.nextInt();
int m = in.nextInt();
StringBuilder s = new StringBuilder();
if(h>=0&&h<24&&m>=0&&m<60) {
if(h>20) {
s.append("twenty ");
char second = String.valueOf(h).charAt(1);
s.append(ch(second));
}else{
s.append(str(String.valueOf(h)));
}
//System.out.println(String.valueOf(m));
if(String.valueOf(m).equals("0")) {//此处原先有错误,拿String与char比较了
//后来改成==,也是不对(报错indexoutof……,因为不经过这个,直接经过最后一个else),因为两个string一定不相等,必须用equals比较内容才行
s.append(" o'clock");
}else if(m>0&&m<=20||m==30||m==40||m==50) {
s.append(" "+str(String.valueOf(m)));
}else {
char first = String.valueOf(m).charAt(0);
//System.out.println(first);
if(first=='2') {//原先写的是ch(first).equals('2')
s.append(" twenty");
}else if(first=='3') {
s.append(" thirty");
}else if(first=='4') {
s.append(" forty");
}else {
s.append(" fifty");
}
char seconds = String.valueOf(m).charAt(1);//此处在整点的情况下会报错,因为只有1位
s.append(" "+ch(seconds));
}
}
System.out.println(s);
}
public static String str(String c) {
String s=null;
switch(c) {
case "0": s="zero"; break;
case "1": s="one"; break;
case "2": s="two"; break;
case "3": s="three";break;
case "4": s="four";break;
case "5": s="five";break;
case "6": s="six";break;
case "7": s="seven";break;
case "8": s="eight";break;
case "9": s="nine";break;
case "10": s="ten";break;
case "11": s="eleven";break;
case "12": s="twelve";break;
case "13": s="thirteen";break;
case "14": s="fourteen";break;
case "15": s="fifteen";break;
case "16": s="sixteen";break;
case "17": s="seventeen";break;
case "18": s="eighteen";break;
case "19": s="nineteen";break;
case "20": s="twenty";break;
case "30": s="thirty";break;
case "40": s="forty";break;
case "50": s="fifty";break;
}
return s;
}
public static String ch(char c) {
String s=null;
switch(c) {
case '1': s="one"; break;
case '2': s="two"; break;
case '3': s="three";break;
case '4': s="four";break;
case '5': s="five";break;
case '6': s="six";break;
case '7': s="seven";break;
case '8': s="eight";break;
case '9': s="nine";break;
}
return s;
}
}