Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
February 7th, 2013, 07:50 PM
 cgodfrey987
Registered User

Join Date: Nov 2012
Posts: 28
Time spent in forums: 4 h 14 m 21 sec
Reputation Power: 0
Convert 234 to two three four, 321 to three two one...etc

Hi I'm in a relatively beginner programming class and need to do a program that will convert any 3 digit number to the written wording of each number. For example, 123 to one two three, or 456 to four five six, or 432 to four three two....etc. We aren't into arrays yet, so is there a way to do this without making a string or char array?

Thanks,

Chris

#2
February 8th, 2013, 06:23 AM
 tvc3mye
Daniel Schildsky

Join Date: Mar 2004
Location: KL, Malaysia.
Posts: 1,540
Time spent in forums: 2 Weeks 4 Days 4 h 3 m 2 sec
Reputation Power: 1620
converting digits to numbers

Well, in that case, you will have to check for each character using the charAt() method of a string instance. You need to use a switch...case statement to check if the digit is 0 ....up to 9, then print out the word as appropriate.
__________________
When the programming world turns decent, the real world will turn upside down.

#3
February 8th, 2013, 07:15 AM
 NormR
Contributing User

Join Date: Aug 2010
Location: SW Missouri
Posts: 3,580
Time spent in forums: 2 Weeks 3 Days 2 h 43 m 25 sec
Reputation Power: 347
If you can't use Strings to get at the digits in the number, another way is to use the % and / operators to extract the digits one at a time. For example 123 % 10 is 3

 Viewing: Dev Shed Forums > Programming Languages > Java Help > Convert 234 to two three four, 321 to three two one...etc