StringTokenizer

Aim: 
To write a java program that reads a line of integers and then displays each integer and the sum of all integers.

Description: 
The StringTokenizer class allows an application to break a string into tokens. The discrete parts of a string are called tokens. Therefore, given an input string, we can enumerate the individual tokens contained in it using StringTokenizer. The default delimiters are whitespace characters. By parsing individual tokens into integers we will get integers and we can add those integers to find the sum.

Program:
import java.util.*;
import java.io.*;
class SumInt
{ public static void main(String args[ ]) throws IOException
{ BufferedReader br = new BufferedReader( new InputStreamReader(
System.in) );
System.out.println("Enter a line of integers : ");
String str= br.readLine();
StringTokenizer sc=new StringTokenizer(str," ");
System.out.println("The integers are:");
int total=0;
while(sc.hasMoreTokens())
{
int k=Integer.parseInt(sc.nextToken());
System.out.println(k);
total=total+k;
}
System.out.println("Sum of all integers:"+total);
}
}