Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiplying Digits in a String
public static int parseString(String digits) {
int product = 1;
//Strips out non-word characters
digits = digits.replaceAll("\\W","");
for (int i = 0; i < digits.length(); i++){
product *= Integer.parseInt(digits.substring(i,(i+1)));
}
return (digits.length() > 0) ? product:0;
/*
try {
for (int i = 0; i < digits.length(); i++){
//
product *= Integer.parseInt(digits.substring(i,(i+1)));
}
}
catch (NumberFormatException e) {
System.out.println(e);
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.