Skip to content

Instantly share code, notes, and snippets.

@bitwiser
Created February 26, 2014 21:09
Show Gist options
  • Save bitwiser/9238597 to your computer and use it in GitHub Desktop.
Save bitwiser/9238597 to your computer and use it in GitHub Desktop.
class TestProgram{
public static void main(String[] srgs){
String s = "abc123";
System.out.println(sumDigits(s));
}
public static int sumDigits(String s){
int l,sum=0;
l = s.length();
for(int i=0;i<l;i++){
if(s.charAt(i)>='0' && s.charAt(i)<='9'){
sum = sum+((int)s.charAt(i)-(int)'0');
}
}
return sum;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment