title: 2 or more digit numbers with delimiters in java
body: <p>I have this basic program that works pretty well when entering single digit numbers. But when calculating an expression with multiple digits, like 1337 - 456 + 32, the program doesn't move on...it acts likes I did nothing.
  It doesn't freeze or output an error message, it just stops.</p>
  <p>here's the code:</p>
  <pre><code>import java.io.*;
  import java.util.*;
  public class Tester {
      public static void main(String args[]) {
          Scanner kb = new Scanner(System.in);
          System.out.print(&quot;Enter number: &quot;);
          String s = kb.nextLine();
          Scanner sc = new Scanner(s);
          //Set delimiters to a plus sign surrounded by any amount of white space...or...
          // a minus sign surrounded by any amount of white space.
          sc.useDelimiter(&quot;\\s*&quot;);
          int sum = 0;
          int temp = 0;
          int intbefore = 0;
          
          if (sc.hasNext(&quot;\\-&quot;)) {
              sc.next();
              if (sc.hasNextInt()) {
                  intbefore = sc.nextInt();
                  int temper = intbefore * 2;
                  intbefore = intbefore - temper; 
              }
          }
          if (sc.hasNextInt()) {
              intbefore = sc.nextInt(); //now its at the sign (intbefore = 5)
          }
          sum = intbefore;
          
          while (sc.hasNext()) {
              if(sc.hasNext(&quot;\\+&quot;)) { //does it have a plus sign?
                  sc.next(); //if yes, move on (now at the number)
                  System.out.println(&quot;got to the next();&quot;);
                  
                  if(sc.hasNextInt()) { //if there's a number
                      temp = sc.nextInt();
                      sum = sum + temp; //add it by the sum (0) and the sum of (5) and (4)
                      System.out.println(&quot;added &quot; + sum);
                  }
              }
              if(sc.hasNext(&quot;\\-&quot;)) {
                  sc.next();
                  System.out.println(&quot;got to the next();&quot;);
                  
                  if (sc.hasNextInt()) {
                      temp = sc.nextInt();
                      sum = sum - temp; //intbefore - temp == 11
                      System.out.println(&quot;intbefore: &quot; + intbefore + &quot;  temp: &quot; + temp);
                      System.out.println(&quot;subtracted &quot; + sum); // subtracted by 11
                  }
              }
          }
          System.out.println(&quot;Sum is: &quot; + sum);
      }
  }
  </code></pre>
  <p>Help with why this happens and what to do to fix it?
  (I'm using netbeans if that helps)</p>
  <p>Also, I'm assuming that the input has a space between each number Ex: 123 + -23 - 5</p>