How do I get integers from a string?
<p>I'm fairly new to Java and I've been stuck on a problem in my Java class.  </p>

<p>Design and write an applet that searches for single-digit numbers
in a text and changes them to their corresponding words. For example, the
string “4 score and 7 years ago” would be converted into “four score and seven
years ago”.  Or if the input were to be "a baseball game has 27 outs" it would become 
"a baseball game has two-seven outs".</p>

<p>I have the applet created and it runs.  I also made it so if a number (between 0 and 99) were entered into the input that it would convert it to text (like 4 to four), but I can't get it to detect numbers within a string like the ones above.<br>
How would I go about making it able to read the string and actually detecting the integers within? </p>

<p>Here's what I have without the GUI components:</p>

<pre><code>private static final String[] numberNames = { "zero", "one", "two", "three", "four",
                                              "five", "six", "seven", "eight", "nine"};
private static String convertNumber(int number) {
      String num;

        if (number % 10 &lt; 10){
          num = numberNames[number % 10];
          number /= 10;
        }
        else {
          num = numberNames[number % 10];
          number /= 10;
        }
        if (number == 0) return num;
        return numberNames[number] + "-" + num;
      }
</code></pre>
