title: Adding multiple numbers using java
body: <p>I am trying to add numbers by scanning a line. I wanted the answer to be computed soon after i press "ENTER". What is the argument i should pass for the delimiter.</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  class add {
     public static void main(String[] args) throws IOException {
        int b=0;
        List&lt;Integer&gt; list  =  new ArrayList&lt;Integer&gt;();
        System.out.println("Enter the numbers");
        Scanner sc = new Scanner(System.in).useDelimiter(" ");
        while(sc.hasNextInt())
        {  
        list.add(sc.nextInt());
         }
        for(int i=0;i&lt;list.size();i++) {
           b += list.get(i);
        }
        System.out.println("The answer is" + b);
     }
  }
  </code></pre>