So I haven't used Java in a couple of semesters so I figured it would be a good idea to work my way through the cattle drive at the JavaRanch site; And I'm having a little trouble expanding the scale of my Say.java program. There are two parts to the assignment:
(1) Write a program that will read in a number from 0 to 99 and spell out that number. The program must also report any values that are out of range.
In other words, I want to type:
(2) expand your program from part one to handle numbers as large as 999,999,999,999.
I am having trouble trying to wrap my brain around how I would do this. The only solution in my mind is a whole bunch of strings that would be concatenated together. I was wondering if I could hear alternate solutions.
Here's the code I have so far:
"If the facts don't fit the theory, get new facts" --Albert Einstein
If you have to convert the number 256 to English text you don't need an array of which entry number 256 is "two hundred and fifty-six". That's the point of the "extend this program" exercise. Instead you need to split the number into two parts, then apply the algorithm to each part, then put the two parts back together in the right way. Can you see how to do that with 256?