Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
482 B
0
Indexable
Never
import java.util.StringTokenizer;
import java.util.Scanner;
public class StringToken {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter the string: ");
		String s = sc.nextLine();
		StringTokenizer q = new StringTokenizer(s);
		int sum = 0;
		while(q.hasMoreTokens()) {
			String temp = q.nextToken();
			int n = Integer.parseInt(temp);
			System.out.println(n);
			sum += n;
		}
		System.out.println("Sum = " + sum);
	}
}
Leave a Comment