try to parse num using parseInt

master
melvinzhang 2015-12-13 10:22:44 +08:00
parent e7378bd9af
commit b7d4b02912
1 changed files with 5 additions and 1 deletions

View File

@ -6,6 +6,11 @@ public class EnglishToInt {
if (num == null) {
return 1;
}
try {
return Integer.parseInt(num);
} catch (final NumberFormatException nfe) {
//do nothing
}
switch (num) {
case "no": return 0;
case "a": return 1;
@ -27,7 +32,6 @@ public class EnglishToInt {
case "fifteen" : return 15;
case "twenty" : return 20;
case "ninety-nine": return 99;
case "100": return 100;
default: throw new RuntimeException("unknown count \"" + num + "\"");
}
}