-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringTokenizerSum.java
More file actions
27 lines (26 loc) · 904 Bytes
/
Copy pathStringTokenizerSum.java
File metadata and controls
27 lines (26 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**********************************************************************
* File :StringTokenizerSum.java
* Description :To find the sum of integer in a given string
* Author :Shraya S Santhosh
* Version :1.0
* Date :28/11/2023
*******************************************************************/
package newproj;
import java.util.StringTokenizer;
import java.util.Scanner;
public class StringTokenizerSum {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter the string :");
String line=sc.nextLine();
StringTokenizer string=new StringTokenizer(line);
int no,sum=0;
System.out.println("Numbers :");
while(string.hasMoreTokens()) {
no=Integer.parseInt(string.nextToken());
System.out.println(no);
sum=sum+no;
}
System.out.println("Sum :"+sum);
}
}