public class Problem17 { public static void main(String[] args) { int numberOfChar = 0; int copy = 0, tmp = 0; String test = ""; String[] table1 = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}; String[] table2 = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"}; String[] table3 = {"", "onehundredand", "twohundredand", "threehundredand", "fourhundredand", "fivehundredand", "sixhundredand", "sevenhundredand", "eighthundredand", "ninehundredand"}; String[] table4 = {"", "onethousand"}; for(int i = 1; i <= 1000; i++) { copy = i; test = ""; if(copy == 1000) { numberOfChar += table4[1].length(); test += table4[1]; } if(copy >= 100 && copy < 1000) { copy = i / 100; numberOfChar += table3[copy].length(); test += table3[copy]; copy = i % 100; } if(copy >= 20 && copy < 100) { tmp = copy; copy /= 10; numberOfChar += table2[copy].length(); test += table2[copy]; copy = tmp % 10; } if(copy > 0 && copy < 20) { numberOfChar += table1[copy].length(); test += table1[copy]; } System.out.println(test); } System.out.println("number of char = " + numberOfChar); }}