The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
Convert 234 to two three four, 321 to three two one...etc
Discuss Convert 234 to two three four, 321 to three two one...etc in the Java Help forum on Dev Shed. Convert 234 to two three four, 321 to three two one...etc Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 7th, 2013, 06:50 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 27
Time spent in forums: 4 h 1 m 34 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
|

February 8th, 2013, 05:23 AM
|
 |
Daniel Schildsky
|
|
Join Date: Mar 2004
Location: KL, Malaysia.
|
|
|
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.
|

February 8th, 2013, 06:15 AM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|