title: Java Numbers to words (0-999)
body: <p>This is my first post, and i'm currently struggling with creating a program which can transform the input of a number into its respective word. My code so far is written below, i can't seem to get the tens to work properly i.e 21,31,41,51 etc..</p>
  
  <pre><code>public class NumberToWords {
      public static void main(String[] args) {
         System.out.print("Number: ");
          int value = In.nextInt();
          int onesDigit;
          int tensDigit;
          String [] ones = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
              "eleven", "tweleve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
  
          String [] tens = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
  
          String [] hundreds = {"one hundred", "two hundred", "three hundred", "four hundred", "five hundred", 
              "six hundred", "seven hundred", "eight hundred", "nine hundred" }; 
    while(value != -1)
   {
     if (value &lt; 20)
      {
          String result = ones[value];
          System.out.println("Result " + result);
          value = In.nextInt();
      }
     if (value &gt; 20 &amp;&amp; value &lt; 100)
      {
          tensDigit = value%10;
          onesDigit = value/10;
          System.out.print("Result " + ones[onesDigit] + " " + tens[tensDigit]);
          value = In.nextInt();
  
      }
   }
  
  }    
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thank you</p>