iLLcheff

Number as Words

Sep 20th, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExerciseTen {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String input = scanner.nextLine();
  8.         int inputNumber = Integer.parseInt(input);
  9.  
  10.         int tens;
  11.         int ones;
  12.  
  13.         if (inputNumber == 0) {
  14.             System.out.print("Zero");
  15.         }
  16. //HUNDREDS
  17.         if (inputNumber >= 100 && inputNumber <= 999) {
  18.             if (inputNumber < 200) {
  19.                 System.out.print("One hundred ");
  20.             }
  21.             if (inputNumber >= 200 && inputNumber < 300) {
  22.                 System.out.print("Two hundred ");
  23.             }
  24.             if (inputNumber >= 300 && inputNumber < 400) {
  25.                 System.out.print("Three hundred ");
  26.             }
  27.             if (inputNumber >= 400 && inputNumber < 500) {
  28.                 System.out.print("Four hundred ");
  29.             }
  30.             if (inputNumber >= 500 && inputNumber < 600) {
  31.                 System.out.print("Five hundred ");
  32.             }
  33.             if (inputNumber >= 600 && inputNumber < 700) {
  34.                 System.out.print("Six hundred ");
  35.             }
  36.             if (inputNumber >= 700 && inputNumber < 800) {
  37.                 System.out.print("Seven hundred ");
  38.             }
  39.             if (inputNumber >= 800 && inputNumber < 900) {
  40.                 System.out.print("Eight hundred ");
  41.             }
  42.             if (inputNumber >= 900) {
  43.                 System.out.print("Nine hundred ");
  44.             }
  45.             if (inputNumber % 100 != 0) {
  46.                 System.out.print("and ");
  47.             }
  48.         }
  49.         tens = inputNumber % 100;
  50. //TENS
  51.         if (tens == 10) {
  52.             if (inputNumber > 99) {
  53.                 System.out.print("ten");
  54.             } else {
  55.                 System.out.print("Ten");
  56.             }
  57.         }
  58.         if (tens == 11) {
  59.             tens -= 11;
  60.             if (inputNumber > 99) {
  61.                 System.out.print("eleven");
  62.             } else {
  63.                 System.out.print("Eleven");
  64.             }
  65.         }
  66.         if (tens == 12) {
  67.             tens -= 12;
  68.             if (inputNumber > 99) {
  69.                 System.out.print("twelve");
  70.             } else {
  71.                 System.out.print("Twelve");
  72.             }
  73.         }
  74.         if (tens == 13) {
  75.             tens -= 13;
  76.             if (inputNumber > 99) {
  77.                 System.out.print("thirteen");
  78.             } else {
  79.                 System.out.print("Thirteen");
  80.             }
  81.         }
  82.         if (tens == 14) {
  83.             tens -= 14;
  84.             if (inputNumber > 99) {
  85.                 System.out.print("fourteen");
  86.             } else {
  87.                 System.out.print("Fourteen");
  88.             }
  89.         }
  90.         if (tens == 15) {
  91.             tens -= 15;
  92.             if (inputNumber > 99) {
  93.                 System.out.print("fifteen");
  94.             } else {
  95.                 System.out.print("Fifteen");
  96.             }
  97.         }
  98.         if (tens == 16) {
  99.             tens -= 16;
  100.             if (inputNumber > 99) {
  101.                 System.out.print("sixteen");
  102.             } else {
  103.                 System.out.print("Sixteen");
  104.             }
  105.         }
  106.         if (tens == 17) {
  107.             tens -= 17;
  108.             if (inputNumber > 99) {
  109.                 System.out.print("seventeen");
  110.             } else {
  111.                 System.out.print("Seventeen");
  112.             }
  113.         }
  114.         if (tens == 18) {
  115.             tens -= 19;
  116.             if (inputNumber > 99) {
  117.                 System.out.print("eighteen");
  118.             } else {
  119.                 System.out.print("Eighteen");
  120.             }
  121.         }
  122.         if (tens == 19) {
  123.             tens -= 19;
  124.             if (inputNumber > 99) {
  125.                 System.out.print("nineteen");
  126.             } else {
  127.                 System.out.print("Nineteen");
  128.             }
  129.         }
  130.         if (tens >= 20 && tens < 30) {
  131.             if (inputNumber > 99) {
  132.                 System.out.print("twenty ");
  133.             } else {
  134.                 System.out.print("Twenty ");
  135.             }
  136.         }
  137.         if (tens >= 30 && tens < 40) {
  138.             if (inputNumber > 99) {
  139.                 System.out.print("thirty ");
  140.             } else {
  141.                 System.out.print("Thirty ");
  142.             }
  143.         }
  144.         if (tens >= 40 && tens < 50) {
  145.             if (inputNumber > 99) {
  146.                 System.out.print("forty ");
  147.             } else {
  148.                 System.out.print("Forty ");
  149.             }
  150.         }
  151.         if (tens >= 50 && tens < 60) {
  152.             if (inputNumber > 99) {
  153.                 System.out.print("fifty ");
  154.             } else {
  155.                 System.out.print("Fifty ");
  156.             }
  157.         }
  158.         if (tens >= 60 && tens < 70) {
  159.             if (inputNumber > 99) {
  160.                 System.out.print("sixty ");
  161.             } else {
  162.                 System.out.print("Sixty ");
  163.             }
  164.         }
  165.         if (tens >= 70 && tens < 80) {
  166.             if (inputNumber > 99) {
  167.                 System.out.print("seventy ");
  168.             } else {
  169.                 System.out.print("Seventy ");
  170.             }
  171.         }
  172.         if (tens >= 80 && tens < 90) {
  173.             if (inputNumber > 99) {
  174.                 System.out.print("eighty ");
  175.             } else {
  176.                 System.out.print("Eighty ");
  177.             }
  178.         }
  179.         if (tens >= 90) {
  180.             if (inputNumber > 99) {
  181.                 System.out.print("ninety ");
  182.             } else {
  183.                 System.out.print("Ninety ");
  184.             }
  185.         }
  186. //ONES
  187.         ones = tens % 10;
  188.         if (ones == 1) {
  189.             if (inputNumber < 10) {
  190.                 System.out.print("One");
  191.             } else {
  192.                 System.out.print("one");
  193.             }
  194.         }
  195.         if (ones == 2) {
  196.             if (inputNumber < 10) {
  197.                 System.out.print("Two");
  198.             } else {
  199.                 System.out.print("two");
  200.             }
  201.         }
  202.         if (ones == 3) {
  203.             if (inputNumber < 10) {
  204.                 System.out.print("Three");
  205.             } else {
  206.                 System.out.print("three");
  207.             }
  208.         }
  209.         if (ones == 4) {
  210.             if (inputNumber < 10) {
  211.                 System.out.print("Four");
  212.             } else {
  213.                 System.out.print("four");
  214.             }
  215.         }
  216.         if (ones == 5) {
  217.             if (inputNumber < 10) {
  218.                 System.out.print("Five");
  219.             } else {
  220.                 System.out.print("five");
  221.             }
  222.         }
  223.         if (ones == 6) {
  224.             if (inputNumber < 10) {
  225.                 System.out.print("Six");
  226.             } else {
  227.                 System.out.print("six");
  228.             }
  229.         }
  230.         if (ones == 7) {
  231.             if (inputNumber < 10) {
  232.                 System.out.print("Seven");
  233.             } else {
  234.                 System.out.print("seven");
  235.             }
  236.         }
  237.         if (ones == 8) {
  238.             if (inputNumber < 10) {
  239.                 System.out.print("Eight");
  240.             } else {
  241.                 System.out.print("eight");
  242.             }
  243.         }
  244.         if (ones == 9) {
  245.             if (inputNumber < 10) {
  246.                 System.out.print("Nine");
  247.             } else {
  248.                 System.out.print("nine");
  249.             }
  250.         }
  251.  
  252.     }
  253. }
  254.  
Advertisement
Add Comment
Please, Sign In to add comment