// Project: TerminalIO // Module: wordtonum // Source code file: Main.java // Input a one digit number in words, then output // the corresponding integer. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter word for a one digit integer: "); String word = in.nextLine( ); // Declare and initialize num to 0 to avoid // an uninitialized variable warning. int num = 0; if (word.equals("zero")) { num = 0; } else if (word.equals("one")) { num = 1; } else if (word.equals("two")) { num = 2; } else if (word.equals("three")) { num = 3; } else if (word.equals("four")) { num = 4; } else if (word.equals("five")) { num = 5; } else if (word.equals("six")) { num = 6; } else if (word.equals("seven")) { num = 7; } else if (word.equals("eight")) { num = 8; } else if (word.equals("nine")) { num = 9; } else { num = -1; } if (num == -1) { System.out.println("Illegal input."); } else { System.out.println("The integer is " + num + "."); } in.close( ); } }