Daniel Ray
Posts: 53
Nickname: budoray
Registered: Oct, 2002
|
|
Re: Newbie code Please help if u can .
|
Posted: May 12, 2004 3:09 AM
|
|
The code below is incomplete and untested. It may have syntax errors.
My approach would be to declare some static final strings for 1-20, 30, 40, 50 ... 90 like so
public static final String ONE = "one"; ... public static final String NINETEEN = "nineteen"; ... public static final String SIXTY = "sixty"; ...
*** Do the same for "and", "hundreds", "thousands" etc (in case you want to use this for values greater than an int)
Will you parse the elements of the array as ints .. easier
int[] ints = {1, 2, 3} // 123
(You will need some exception handling to parse a String using the Integer method parseInt("1") to ensure you have a valid int.)
I would then start at the end of the array .. ints.length and step backwards in groups of three because we write larger numbers like 32,500 and no matter where 500 ends up we still say it as five hundred .. five hundred thousand .. five hundred million.
If the length of the group of ints is less than 3 .. then I would do something similar to the above for teens and so on.
The only tricky thing that sticks out is how to deal with 0, 00, and 000. The only time you might print zero is if ints.length = 1. This is where the "and" comes in from where I marked ***.
I used to help out here quite a bit, but I got hammered for 'supplying' code. Give this an honest attempt and if you still need help .. I'll do what I can.
Regards, Ray
|
|