Advertisement
borkins

16a. Numbers 0..100 to Text

Mar 24th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.83 KB | None | 0 0
  1. /**
  2.  * Project: Simple_Conditions - created by borkins on 2017-03-25.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _16a_Numbers_0_100_toText
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner scan = new Scanner(System.in);
  12.        
  13.         int number = Integer.parseInt(scan.nextLine());
  14.        
  15.         int units = number % 10;
  16.         int tenths = number / 10;
  17.        
  18.         String unitsEng = "";
  19.         String tenthsEng = "";
  20.        
  21.         if (units == 0) {
  22.             unitsEng = "zero";
  23.         }
  24.         else if (units == 1) {
  25.             unitsEng = "one";
  26.         }
  27.         else if (units == 2) {
  28.             unitsEng = "two";
  29.         }
  30.         else if (units == 3) {
  31.             unitsEng = "three";
  32.         }
  33.         else if (units == 4) {
  34.             unitsEng = "four";
  35.         }
  36.         else if (units == 5) {
  37.             unitsEng = "five";
  38.         }
  39.         else if (units == 6) {
  40.             unitsEng = "six";
  41.         }
  42.         else if (units == 7) {
  43.             unitsEng = "seven";
  44.         }
  45.         else if (units == 8) {
  46.             unitsEng = "eight";
  47.         }
  48.         else if (units == 9) {
  49.             unitsEng = "nine";
  50.         }
  51.        
  52.         if (tenths == 1)
  53.         {
  54.             if (units == 0) {
  55.                 tenthsEng = "ten";
  56.             }
  57.             else if (units == 1) {
  58.                 tenthsEng = "eleven";
  59.             }
  60.             else if (units == 2) {
  61.                 tenthsEng = "twelve";
  62.             }
  63.             else if (units == 3) {
  64.                 tenthsEng = "thirteen";
  65.             }
  66.             else if (units == 4) {
  67.                 tenthsEng = "fourteen";
  68.             }
  69.             else if (units == 5) {
  70.                 tenthsEng = "fifteen";
  71.             }
  72.             else if (units == 6) {
  73.                 tenthsEng = "sixteen";
  74.             }
  75.             else if (units == 7) {
  76.                 tenthsEng = "seventeen";
  77.             }
  78.             else if (units == 8) {
  79.                 tenthsEng = "eighteen";
  80.             }
  81.             else if (units == 9) {
  82.                 tenthsEng = "nineteen";
  83.             }
  84.         }
  85.         else if (tenths == 2) {
  86.             tenthsEng = "twenty";
  87.         }
  88.         else if (tenths == 3) {
  89.             tenthsEng = "thirty";
  90.         }
  91.         else if (tenths == 4) {
  92.             tenthsEng = "forty";
  93.         }
  94.         else if (tenths == 5) {
  95.             tenthsEng = "fifty";
  96.         }
  97.         else if (tenths == 6) {
  98.             tenthsEng = "sixty";
  99.         }
  100.         else if (tenths == 7) {
  101.             tenthsEng = "seventy";
  102.         }
  103.         else if (tenths == 8) {
  104.             tenthsEng = "eighty";
  105.         }
  106.         else if (tenths == 9) {
  107.             tenthsEng = "ninety";
  108.         }
  109.        
  110.         // If either conditions is true, print "invalid number".
  111.         if (number < 0 || number > 100) {
  112.             System.out.println("invalid number");
  113.         }
  114.         // In that point we are sure that the number is in the range 0..100.
  115.         // If true, number is between 0 and 9, then print numbers: 'zero', 'one', 'two'...'nine'.
  116.         else if (number < 10) {
  117.             System.out.println(unitsEng);
  118.         }
  119.         // If number is between 10 and 19, print numbers: 'ten', 'eleven', 'twelve'...'nineteen'.
  120.         // OR if number is between 20..99 AND the digit in the units is 0,
  121.         // print numbers: 'twenty', 'thirty', 'forty'...'ninety'.
  122.         else if (number < 20 || (number < 100 && units == 0)) {
  123.             System.out.println(tenthsEng);
  124.         }
  125.         // If number is between 20 and 99, print the numbers with two words.
  126.         else if (number < 100) {
  127.             System.out.println(tenthsEng + " " + unitsEng);
  128.         }
  129.         // The number is 100, print 'one hundred'.
  130.         else {
  131.             System.out.println("one hundred");
  132.         }
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement