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.
import java.io.*;
import java.util.*;
class add {
public static void main(String[] args) throws IOException {
int b=0;
List<Integer> list = new ArrayList<Integer>();
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<list.size();i++) {
b += list.get(i);
}
System.out.println("The answer is" + b);
}
}