Advertisement
Guest User

Untitled

a guest
Feb 8th, 2022
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem10 {
  4.  
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. String number = sc.nextLine();
  8. int i = Integer.parseInt(number);
  9. String[] oneDigit = {"Zero", "one", "two", "three","four", "five", "six", "seven","eight", "nine","ten" };
  10. String[] tens = {"eleven", "twelve", "thirteen","fourteen", "fifteen", "sixteen", "seventeen","eighteen", "nineteen"};
  11. String[] tens2 = {"twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
  12. String output = "";
  13. int temp;
  14. char tempNum1;
  15. char tempNum2;
  16. char tempNum3;
  17. String upperCase;
  18.  
  19.  
  20. if (i >= 0 && i <= 10) {
  21. output = oneDigit[i];
  22. upperCase = output.substring(0, 1).toUpperCase() + output.substring(1);
  23. System.out.println(upperCase);
  24. } else if (i > 10 && i < 20) {
  25. output = tens[i - 11];
  26. upperCase = output.substring(0, 1).toUpperCase() + output.substring(1);
  27. System.out.println(upperCase);
  28. } else if (i / 100 > 0) {
  29. tempNum1 = number.charAt(0);
  30. int num1 = Integer.parseInt(String.valueOf(tempNum1));
  31. tempNum2 = number.charAt(1);
  32. int num2 = Integer.parseInt(String.valueOf(tempNum2));
  33. tempNum3 = number.charAt(2);
  34. int num3 = Integer.parseInt(String.valueOf(tempNum3));
  35. if (num2 > 0 && num3 > 0) {
  36. output = oneDigit[num1] + " " + "hundred" + " " + tens2[num2 - 2] + " " + oneDigit[num3];
  37. } else if (num2 == 0 && num3 == 0) {
  38. output = oneDigit[num1] + " " + "hundred" ;
  39. } else if (num2 == 0 && num3 > 0) {
  40. output = oneDigit[num1] + " " + "hundred" + " " + "and" + " "+ oneDigit[num3];
  41. } else {
  42. output = oneDigit[num1] + " " + "hundred" + " " + "and" + " " + tens2[num2 - 2];
  43. }
  44. upperCase = output.substring(0, 1).toUpperCase() + output.substring(1);
  45. System.out.println(upperCase);
  46. } else if (i / 10 > 0) {
  47. tempNum1 = number.charAt(0);
  48. int num1 = Integer.parseInt(String.valueOf(tempNum1));
  49. tempNum2 = number.charAt(1);
  50. int num2 = Integer.parseInt(String.valueOf(tempNum2));
  51.  
  52. if (num2 > 0) {
  53. output = tens2[num1 - 2] + " " + oneDigit[num2];
  54. } else {
  55. output = tens2[num1 - 2];
  56. }
  57. upperCase = output.substring(0, 1).toUpperCase() + output.substring(1);
  58. System.out.println(upperCase);
  59. }
  60.  
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement