CW 32 - Number Letter Counts

DUE

Number Letter Counts

Project Euler - Problem 17

Save your work here: .../APCSA_1/apcsa-assignments-YourUsername/classwork/32_recursion_number_letters/NumberLetter.java

This problem must be solved using recursion.

If the numbers 1 to 5 are to are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.

If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?

NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of "and" when writing out numbers is in compliance with British usage.

Think about the problem:

First how can you implement this method to return the number in letters:

public static String numberToWords(int number) {

}

Let's do it from 1-1000 to have the total number of letters in all those numbers:

Declare an integer variable 'result' to store total number of letters
for each number from 1 to 1000
	call recursive method numberToWords(number here), this return number in words
	get the length of the word returned from the recursive method and add it to 'result'

Debugging and Testing: