Digit as Word

Description

Write a program that read a digit [0-9] from the console, and depending on the input, shows the digit as a word (in English).

  • Print “not a digit” in case of invalid input.
  • Use a switch statement.

Input

  • The input consists of one line only, which contains the digit.

Output

  • Output a single line - should the input be a valid digits, print the english word for the digits. Otherwise, print “not a digit” .

Constraints

  • The input will never be an empty line.

Sample tests

Input Output
-0.1 not a digit
1 one
9 nine
-9 not a digit
kek not a digit

Здравейте, имам проблем с тази задача, не ми приема решението, бих искал да знам къде греша.

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

    String digit = scanner.nextLine();

    switch (digit){
        case "0" :
            System.out.println("null");
        case "1":
            System.out.println("one");
            break;
        case "2":
            System.out.println("two");
            break;
        case "3":
            System.out.println("three");
            break;
        case "4":
            System.out.println("four");
            break;
        case "5":
            System.out.println("five");
            break;
        case "6":
            System.out.println("six");
            break;
        case "7":
            System.out.println("seven");
            break;
        case "8":
            System.out.println("eight");
            break;
        case "9":
            System.out.println("nine");
            break;
        default:
            System.out.println("not a digit");
    }

}

}

Здравей,
пробвай със “zero” за 0 ? :slight_smile:

Мерси, обърках се понеже изтървах 0 - та още в началото и съм я написал на немски в последствие хахах.