# Euler Problem 17

If the numbers 1 to 5 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.

Make sure you check your spelling, otherwise its a long day of counting.

public class Euler17
{
public static void main(String[] args)
{
System.out.print(“Problem 17:\n”);
Euler17 e = new Euler17();
System.out.print(“Answer = ” + e.Problem()+ “\n”);
}
public String Problem ()
{
String list = “”, number = “”;
int hun, ten, one;
for (int i = 1; i <= 999; i++)
{
number = “”;
hun = (int)Math.floor(i/100)*100;
ten = (int)Math.floor((i-hun)/10)*10;
one = (int)Math.floor(i-hun-ten);
if (hun != 0)
{
number += Hundreds(hun);
if (i % 100 != 0)
number += “and”;
}
if (ten <= 19)
{
number += Teens(ten+one);
}
else if (ten >= 20)
{
number += Tens(ten);
}
if (one != 0 && ten >= 20)
{
number += Ones(one);
}
System.out.print(i+”:”+number+”:”+number.length()+”\n”);
list += number;
}
list += “OneThousand”;
System.out.print(1000+”:”+”OneThousand:11\n”);
return String.valueOf(list.length());
}
public String Ones (int num)
{
if (num == 1)
else if (num == 2)
else if (num == 3)
else if (num == 4)
else if (num == 5)
else if (num == 6)
else if (num == 7)
else if (num == 8)
else if (num == 9)
}
public String Teens (int num)
{
if (num < 10)
else if (num == 10)
else if (num == 11)
else if (num == 12)
else if (num == 13)
else if (num == 14)
else if (num == 15)
else if (num == 16)
else if (num == 17)
else if (num == 18)
else if (num == 19)
}
public String Tens (int num)
{
if (num == 10)
else if (num == 20)
else if (num == 30)
else if (num == 40)
else if (num == 50)
else if (num == 60)
el
se if (num == 70)