You have to take care of all the cases, namely: all the other cases that you described in the if-else chain. To fix this, I would choose an exception, indicating that a digit is not possible:
public static String numTxt (int x) { String txt[] = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"}; if (0 <= x && x <= 9) return txt[x]; throw new IllegalArgumentException("Unsupported digit!"); }
Martijn courteaux
source share