File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Convert numbers to words Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Convert numbers to words" Watch "Convert numbers to words" New topic
Author

Convert numbers to words

Gian Aznar
Greenhorn

Joined: Jan 01, 2013
Posts: 2
i cant get 11 - 19... its output will be TenOneEleven

please look at the codes
Gian Aznar
Greenhorn

Joined: Jan 01, 2013
Posts: 2
please do reply
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11314
    
  16

1. Please don't hijack someone else's post. We have plenty of room around here, so just create your own thread. I have split your two posts into a new thread.
2. Take a look at our HowToAskQuestionsOnJavaRanch FAQ. There are a LOT of tips on there on how to make posts here that give you the best chance of being answered.
3. I am about to send you a private message. Please check there in a minute or two.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Also, please remember to UseCodeTags (<-click) next time you post code. I changed your post to include them this time.

As for your problem: The issue is one of logic. You have identified some special cases, when the length of the input is > 1 and the tens digit is equal to 1. But you do not prevent normal output from happening in those special cases. Your option is to do a nested series of ifs like this (pseudocode):

This is pseudocode, and it doesn't handle the 100s digit, but you can add that yourself.

Another option, which would require less change in your code, is when you reach the special case code don't add to the already present output string, instead, simply replace it.

There are a number of other optimizations that can be made, but since this is a beginners programming exercise I won't go into them.


Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert numbers to words