-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPranit_series.java
More file actions
30 lines (27 loc) · 850 Bytes
/
Pranit_series.java
File metadata and controls
30 lines (27 loc) · 850 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
28
29
30
import java.util.Scanner;
public class Pranit_series {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int sum=0;
String str=sc.nextLine();
str.trim();
for(int i=0;i<str.length();i++){
String w="";
for(int j=i;j<str.length();j++){
char ch=str.charAt(j);
if(ch>=48 && ch<=57){
w+=ch;
}
else if(ch==32){
break;
}
}
w.trim();
System.out.println(w);
sum+=Integer.parseInt(w);
}
System.out.println("Sum : "+sum);
}
}
// Sum of the string entry " 12 13 14 " without using split function.
// getting java.lang.NumberFormatException when tried, check logic and mend errors