Advertisement
Guest User

Untitled

a guest
Mar 21st, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OnetoHundred {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int a = Integer.parseInt(scanner.nextLine());
  7. int b = 0;
  8. int c = 0;
  9. String bword = "";
  10. String cword = "";
  11.  
  12. if (a < 0 || a > 100) {
  13. System.out.println("invalid number");
  14. } else if (a == 0) {
  15. System.out.println("zero");
  16. } else if (a == 100) {
  17. System.out.println("one hundred");
  18. } else if (a > 0 && a < 20) {
  19. if (a == 1) {
  20. System.out.println("one");
  21. }
  22. if (a == 2) {
  23. System.out.println("two");
  24. }
  25. if (a == 3) {
  26. System.out.println("three");
  27. }
  28. if (a == 4) {
  29. System.out.println("four");
  30. }
  31. if (a == 5) {
  32. System.out.println("five");
  33. }
  34. if (a == 6) {
  35. System.out.println("six");
  36. }
  37. if (a == 7) {
  38. System.out.println("seven");
  39. }
  40. if (a == 8) {
  41. System.out.println("eight");
  42. }
  43. if (a == 9) {
  44. System.out.println("nine");
  45. }
  46. if (a == 10) {
  47. System.out.println("ten");
  48. }
  49. if (a == 11) {
  50. System.out.println("eleven");
  51. }
  52. if (a == 12) {
  53. System.out.println("twelve");
  54. }
  55. if (a == 13) {
  56. System.out.println("thirteen");
  57. }
  58. if (a == 14) {
  59. System.out.println("fourteen");
  60. }
  61. if (a == 15) {
  62. System.out.println("fifteen");
  63. }
  64. if (a == 16) {
  65. System.out.println("sixteen");
  66. }
  67. if (a == 17) {
  68. System.out.println("seventeen");
  69. }
  70. if (a == 18) {
  71. System.out.println("eighteen");
  72. }
  73. if (a == 19) {
  74. System.out.println("nineteen");
  75. }
  76. } else if (a > 19 && a < 100) {
  77. b = a / 10;
  78. c = a % 10;
  79. if (b == 2)
  80. bword = "twenty";
  81. if (b == 3)
  82. bword = "thirty";
  83. if (b == 4)
  84. bword = "forty";
  85. if (b == 5)
  86. bword = "fifty";
  87. if (b == 6)
  88. bword = "sixty";
  89. if (b == 7)
  90. bword = "seventy";
  91. if (b == 8)
  92. bword = "eighty";
  93. if (b == 9)
  94. bword = "ninety";
  95. if (c == 1)
  96. cword = "one";
  97. if (c == 2)
  98. cword = "two";
  99. if (c == 3)
  100. cword = "three";
  101. if (c == 4)
  102. cword = "four";
  103. if (c == 5)
  104. cword = "five";
  105. if (c == 6)
  106. cword = "six";
  107. if (c == 7)
  108. cword = "seven";
  109. if (c == 8)
  110. cword = "eight";
  111. if (c == 9)
  112. cword = "nine";
  113. if (c == 0) {
  114. System.out.println(bword);
  115. } else System.out.println(bword + " " + cword);
  116. }
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement