How to parse this input?
<p>I'm trying to create a calculator that takes a string that can be in 4 different formats:</p>

<pre><code>input: add 1 2 13 5 together
       =&gt; 1 + 2 + 13 + 5 = 21
input: add 9 to 10
       =&gt; 9 + 10 = 19
input: subtract 5 from 13
       =&gt; 13 - 5 = 8
input: bye
       =&gt; end program
</code></pre>

<p>I've set up my code like this: </p>

<pre><code>import java.util.*;

    class Calculator {
      public static void main(String[] args) {
        System.out.println("yes&gt;" )
        Scanner zip = new Scanner(System.in);
        String input = zip.nextLine(); 

        if (input.equals("bye")) 
           System.exit(0); 
        else if (input.substring(0, 1) == "a") //assume first cmd is add
           (integer.ParseInt(input.subtring(3, BLANK) //extract first number
</code></pre>

<p>My problem is that I don't know the index of the numbers in the string. I wanted to do it like this: </p>

<p>if (input.substring(0, 3) == "add") => the next digit will be a number. parse integer.substring(3, BLANK). BLANK should be the index of the space character. then that number needs to be placed into a variable, and the program needs to check for all other integers. </p>

<p>I'm a little confused at how to approach this. What if there are 500 numbers that need to be added (or subtracted?) Is there a way to do this recursively, somehow? This program is supposed to use regular expressions which I've read about, but I'm not sure how to implement. </p>

<p>Any help would be really appreciated. Thanks in advance</p>
