aneliyanestorova

digit_as_word

Mar 28th, 2019
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import java.util.InputMismatchException;
  2. import java.util.Scanner;
  3. public class DigitAsWord {
  4.  
  5.  
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9.  
  10. try {
  11. int num ;
  12. num = scanner.nextInt();
  13. if (num == 0 ) {
  14. System.out.println("zero");
  15. } else if (num == 1) {
  16. System.out.println("one");
  17. } else if (num == 2) {
  18. System.out.println("two");
  19. } else if (num == 3) {
  20. System.out.println("three");
  21. } else if (num == 4) {
  22. System.out.println("four");
  23. } else if (num == 5) {
  24. System.out.println("five");
  25. } else if (num == 6) {
  26. System.out.println("six");
  27. } else if (num == 7) {
  28. System.out.println("seven");
  29. } else if (num == 8) {
  30. System.out.println("eight");
  31. } else if (num == 9) {
  32. System.out.println("nine");
  33. } else {
  34. System.out.print("not a digit");
  35. }
  36.  
  37. } catch (InputMismatchException ex) {
  38. System.out.println("not a digit.");
  39.  
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment