NumericToWord { public static String convert(Integer n) { if (n < 0) { return "minus " + convert(-n); } if (n < 20) { return units[n]; } if (n < 100) { return tens[n / 10] + ((n % 10 != 0) ? " " : "") + units[n % 10]; } if (n < 1000) { return units[n / 100] + " hundred" + ((n % 100 != 0) ? " " : "") + convert(n % 100); } if (n < 1000000) { return convert(n / 1000) + " thousand" + ((n % 1000 != 0) ? " " : "") + convert(n % 1000); } if (n < 1000000000) { return convert(n / 1000000) + " million" + ((n % 1000000 != 0) ? " " : "") + convert(n % 1000000); } return convert(n / 1000000000) + " billion" + ((n % 1000000000 != 0) ? " " : "") + convert(n % 1000000000); } private  NumericToWord(); static String convert(Integer n);  }
@Test public void simpleConvert() throws Exception { assertEquals("Three", convert(3)); }
@Test public void complexConvert() throws Exception { assertEquals("Four hundred Fifty One", convert(451)); }