1
package org.apache.lucene.util;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
21
public class English {
23
public static String intToEnglish(int i) {
24
StringBuffer result = new StringBuffer();
25
intToEnglish(i, result);
26
return result.toString();
29
public static void intToEnglish(int i, StringBuffer result) {
31
result.append("zero");
35
result.append("minus ");
38
if (i >= 1000000000) { // billions
39
intToEnglish(i/1000000000, result);
40
result.append("billion, ");
43
if (i >= 1000000) { // millions
44
intToEnglish(i/1000000, result);
45
result.append("million, ");
48
if (i >= 1000) { // thousands
49
intToEnglish(i/1000, result);
50
result.append("thousand, ");
53
if (i >= 100) { // hundreds
54
intToEnglish(i/100, result);
55
result.append("hundred ");
60
case 9 : result.append("ninety"); break;
61
case 8 : result.append("eighty"); break;
62
case 7 : result.append("seventy"); break;
63
case 6 : result.append("sixty"); break;
64
case 5 : result.append("fifty"); break;
65
case 4 : result.append("forty"); break;
66
case 3 : result.append("thirty"); break;
67
case 2 : result.append("twenty"); break;
76
case 19 : result.append("nineteen "); break;
77
case 18 : result.append("eighteen "); break;
78
case 17 : result.append("seventeen "); break;
79
case 16 : result.append("sixteen "); break;
80
case 15 : result.append("fifteen "); break;
81
case 14 : result.append("fourteen "); break;
82
case 13 : result.append("thirteen "); break;
83
case 12 : result.append("twelve "); break;
84
case 11 : result.append("eleven "); break;
85
case 10 : result.append("ten "); break;
86
case 9 : result.append("nine "); break;
87
case 8 : result.append("eight "); break;
88
case 7 : result.append("seven "); break;
89
case 6 : result.append("six "); break;
90
case 5 : result.append("five "); break;
91
case 4 : result.append("four "); break;
92
case 3 : result.append("three "); break;
93
case 2 : result.append("two "); break;
94
case 1 : result.append("one "); break;
95
case 0 : result.append(""); break;
99
public static void main(String[] args) {
100
System.out.println(intToEnglish(Integer.parseInt(args[0])));