import javax.swing.*;
public class word {
private static final String[] simple= { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "evelen", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
"eightteen", "nineteen" };
private static final String[] tens= { null, null, "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
public static String say(int number) {
return say(number, true); //default true
}
private static String say(int number, boolean sayZero) {
//simulate 123
if (number < 0) return "negative "+say(-number, sayZero); //is 123 < 0? False
if (number == 0) return sayZero?simple[number]:""; //is 123 < 0 ? False
if (number < 20) return simple[number]; //is 123 < 0? false
if (number < 100) return tens[number/10]+say(number%10, false); //is 100 < 100? false
if (number < 1000) return say(number/100, false)+" hundred "+say(number%100); //is 100 < 1000? true--execute say(1) hundred
if (number < 1000000) return say(number/1000, false)+" thousand"+say(number%1000, false);
if (number < 1000000000) return say(number/1000000, false)+" million "+say(number%1000000, false);
return say(number/1000000000, false)+"billion "+say(number%1000000000, false);
}
public static void main(String[] args) {
String say = JOptionPane.showInputDialog("Enter a number");
int speak = Integer.parseInt(say);
JOptionPane.showMessageDialog(null,say(speak));
}
}