Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int sum(String str) {
- int result =0;
- String numberstr= "";
- char[] textchararr= str.toCharArray();
- for(int i=0; i<textchararr.length ;i++ ) {
- char c= textchararr[i];
- if(c>='0'&& c<= '9') {
- numberstr +=c ;
- if( i== textchararr.length -1) {
- result += Integer.parseInt(numberstr);
- }
- }
- else if(!numberstr.equals("")) {
- result += Integer.parseInt(numberstr);
- numberstr ="";
- }
- }
- return result ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement