#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    28
    Rep 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. #2
  3. Daniel Schildsky
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2004
    Location
    KL, Malaysia.
    Posts
    1,540
    Rep Power
    1621

    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.
  4. #3
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep 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

IMN logo majestic logo threadwatch logo seochat tools logo