質問編集履歴
4
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Javaで(1~100000000)までの数字を英語に変換する方法を教えてください。
|
2
2
|
|
3
3
|
(浮動小数点も含める)
|
4
|
+
|
5
|
+
0~100まではできたのですが浮動小数点も含めるやり方が全く分かりません。
|
4
6
|
|
5
7
|
|
6
8
|
|
3
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,8 +6,100 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
ソースコード
|
9
|
+
一応昨日書いたソースコードです。
|
10
10
|
|
11
|
-
public stacic void main(string()args){scanner
|
12
11
|
|
12
|
+
|
13
|
+
import java.io.*;
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
public class EnglishNumber {
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
public static void main(String[] args) {
|
22
|
+
|
23
|
+
try {
|
24
|
+
|
25
|
+
String input = "";
|
26
|
+
|
27
|
+
while (!(input = inputNumber()).equals("")) {
|
28
|
+
|
29
|
+
String number = toEnglishNumber(input);
|
30
|
+
|
31
|
+
System.out.println(number);
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
} catch (IOException ie) {
|
36
|
+
|
37
|
+
ie.printStackTrace();
|
38
|
+
|
39
|
+
} catch (NumberFormatException ne) {
|
40
|
+
|
41
|
+
System.out.println("数字でないか、0から99の数字ではありません。");
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
public static String inputNumber() throws IOException {
|
50
|
+
|
51
|
+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
52
|
+
|
53
|
+
System.out.print("0から99の数字を入力してください。");
|
54
|
+
|
55
|
+
return br.readLine();
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
public static String toEnglishNumber(String input) throws NumberFormatException {
|
62
|
+
|
63
|
+
final String[] eNum1 = {"zero", "one", "two", "three", "four",
|
64
|
+
|
65
|
+
"five", "six", "seven", "eight", "nine",
|
66
|
+
|
67
|
+
"ten", "eleven", "twelve", "thirteen", "fourteen",
|
68
|
+
|
69
|
+
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
|
70
|
+
|
71
|
+
StringBuffer number = null;
|
72
|
+
|
73
|
+
int num = Integer.parseInt(input);
|
74
|
+
|
75
|
+
if (num < 0 || num > 99) {
|
76
|
+
|
13
|
-
|
77
|
+
throw new NumberFormatException();
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
if (num < 20) {
|
82
|
+
|
83
|
+
number = new StringBuffer(eNum1[num]);
|
84
|
+
|
85
|
+
} else {
|
86
|
+
|
87
|
+
final String[] eNum2 = {"twenty", "thirty", "forty", "fifty", "sixty",
|
88
|
+
|
89
|
+
"seventy", "eighty", "ninety"};
|
90
|
+
|
91
|
+
number = new StringBuffer(eNum2[input.charAt(0) - 50]);
|
92
|
+
|
93
|
+
if (input.charAt(1) != '0') {
|
94
|
+
|
95
|
+
number.append("-").append(eNum1[input.charAt(1) - 48]);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
return number.toString();
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,13 @@
|
|
1
1
|
Javaで(1~100000000)までの数字を英語に変換する方法を教えてください。
|
2
2
|
|
3
3
|
(浮動小数点も含める)
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
ソースコード
|
10
|
+
|
11
|
+
public stacic void main(string()args){scanner
|
12
|
+
|
13
|
+
stdin=new scanner(systm.in);
|