You should be splitting your semicolon-separated input on ;, and then iterating each term in a loop:

Scanner scanner = new Scanner(System.in);
String input = scanner.next();
String[] nums = input.split(";");
String num = "";

for (String number : nums) {
    if ("zero".equals(number))
        num = num + "0";
    else if ("one".equals(number))
        num = num + "1";
    else if ("two".equals(number))
        num = num + "2";
    else if ("three".equals(number))
        num = num + "3";
    else if ("four".equals(number))
        num = num + "4";
    else if ("five".equals(number))
        num = num + "5";
    else if ("six".equals(number))
        num = num + "6";
    else if ("seven".equals(number))
        num = num + "7";
    else if ("eight".equals(number))
        num = num + "8";
    else if ("nine".equals(number))
        num = num + "9";
}

System.out.println("input:  " + input);
System.out.println("output: " + num);

For an input of zero;six;eight;two this was the output from the above script:

input:  zero;six;eight;two
output: 0682

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top