暴力破解就完事儿了,要注意一个点就是0也要考虑进去,一开始没考虑0哇了好几次。
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
String x = sc.next();
int a = Integer.parseInt(x);
Map map = new TreeMap();
map.put(0,"zero");
map.put(1,"one");
map.put(2,"two");
map.put(3,"three");
map.put(4,"four");
map.put(5,"five");
map.put(6,"six");
map.put(7,"seven");
map.put(8,"eight");
map.put(9,"nine");
map.put(10,"ten");
map.put(20,"twenty");
map.put(30,"thirty");
map.put(40,"forty");
map.put(50,"fifty");
map.put(60,"sixty");
map.put(70,"seventy");
map.put(80,"eighty");
map.put(90,"ninety");
if(a >= 10){
if(a < 20) {
if(a == 10) System.out.println(map.get(10));
if(a == 11) System.out.println("eleven");
if(a == 12) System.out.println("twelve");
if(a == 13) System.out.println("thirteen");
if(a == 14) System.out.println("fourteen");
if(a == 15) System.out.println("fifteen");
if(a == 16) System.out.println("sixteen");
if(a == 17) System.out.println("seventeen");
if(a == 18) System.out.println("eighteen");
if(a == 19) System.out.println("nineteen");
}
if(20 <= a && a<30) {
if(a != 20) System.out.println(map.get(20)+"-"+map.get(a%10));
else System.out.println(map.get(20));
}
if(30 <= a && a<40) {
if(a != 30) System.out.println(map.get(30)+"-"+map.get(a%10));
else System.out.println(map.get(30));
}
if(40 <= a && a<50) {
if(a != 40) System.out.println(map.get(40)+"-"+map.get(a%10));
else System.out.println(map.get(40));
}
if(50 <= a && a<60) {
if(a != 50) System.out.println(map.get(50)+"-"+map.get(a%10));
else System.out.println(map.get(50));
}
if(60 <= a && a<70) {
if(a != 60) System.out.println(map.get(60)+"-"+map.get(a%10));
else System.out.println(map.get(60));
}
if(70 <= a && a<80) {
if(a != 70) System.out.println(map.get(70)+"-"+map.get(a%10));
else System.out.println(map.get(70));
}
if(80 <= a && a<90) {
if(a != 80) System.out.println(map.get(80)+"-"+map.get(a%10));
else System.out.println(map.get(80));
}
if(90 <= a && a<100) {
if(a != 90) System.out.println(map.get(90)+"-"+map.get(a%10));
else System.out.println(map.get(90));
}
}else{
System.out.println(map.get(a));
}
}
}
}