Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. public static int sum(String str) {
  2. int result =0;
  3. String numberstr= "";
  4. char[] textchararr= str.toCharArray();
  5. for(int i=0; i<textchararr.length ;i++ ) {
  6. char c= textchararr[i];
  7. if(c>='0'&& c<= '9') {
  8. numberstr +=c ;
  9. if( i== textchararr.length -1) {
  10. result += Integer.parseInt(numberstr);
  11. }
  12. }
  13. else if(!numberstr.equals("")) {
  14. result += Integer.parseInt(numberstr);
  15. numberstr ="";
  16. }
  17. }
  18. return result ;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement