File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ 03Ju23st 15te5ll10 12me6 3the ti45me 09f567or 06bu7s 23
2
+ From the Given string print sum of the numbers given in the string
3
+ 3+23+15+5+10+12+6+3+45+9+567+6+7+23=734
Original file line number Diff line number Diff line change
1
+ class FindSum {
2
+ public static void main (String [] args ) {
3
+ String str ="03Ju23st 15te5ll10 12me6 3the ti45me 09f567or 06bu7s 23" ;
4
+ int num =0 ;
5
+ int sum =0 ;
6
+ String numStr ="" ;
7
+ for (int i =0 ;i <str .length ();i ++){
8
+ if (str .charAt (i )>='0' && str .charAt (i )<='9' ){
9
+ numStr +=str .charAt (i );
10
+ }else {
11
+ if (numStr .length ()>0 )
12
+ num =Integer .parseInt (numStr );
13
+ sum =sum +num ;
14
+ numStr ="" ;
15
+ }
16
+ }
17
+ if (numStr .length ()>0 )
18
+ {
19
+ num =Integer .parseInt (numStr );
20
+ sum =sum +num ;
21
+ }
22
+ System .out .println (sum );
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments