tan8888
asked on
How to use Java to convert numbers to words.
Hi, I'm trying to write a java code to convert numbers to words, but I somewhat can't find a way to finish it. The application needs two dialog box. The first one ask the user to enter a 4 digit number. The second one shows the result (ex. 123 is equal to one hundred twenty three). Below is what I have so far. I have put the part that I don't how to finish in the notation. Could you guys please give me a hand, or referr me to some similar example? Thank you very much.
import javax.swing.JOptionPane
public class NumberConverterApp {
public static void main (String[] args){
String choice="";
while (!(choice.equalsIgnoreCase ("X"))){
//[how to get and parse input?]
String[] units = {"one, "two", "three, "four", "five", "six", "seven", "eight", "nine");
String[] teens{"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
String[] tens ={"twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"};
String word = "";
if (num.length == 4){
//[how to convert to words?]
}
choice = JOptionPane.showInputDialo g(numbers + " is equal to \n"
+ word + "\n Press enter to continue or 'x' to exit.");
}//end while
System.exit(0);
}
}
import javax.swing.JOptionPane
public class NumberConverterApp {
public static void main (String[] args){
String choice="";
while (!(choice.equalsIgnoreCase
//[how to get and parse input?]
String[] units = {"one, "two", "three, "four", "five", "six", "seven", "eight", "nine");
String[] teens{"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
String[] tens ={"twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"};
String word = "";
if (num.length == 4){
//[how to convert to words?]
}
choice = JOptionPane.showInputDialo
+ word + "\n Press enter to continue or 'x' to exit.");
}//end while
System.exit(0);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
they both contain working examples to convert numbers into words, what exactly do you need help with?
ASKER