import java.util.regex.*; import java.util.*; class WordInput { public static void main(String[] args) { Scanner userin = new Scanner(System.in); String word; System.out.print("Enter a word: "); try { word = userin.next("[A-Za-z]+"); System.out.printf("That word has %d letters.\n", word.length()); } catch (InputMismatchException e) { System.out.println("That wasn't a word."); } } }