Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Trying to write a Java program code for this problem.. Given a string, return the sum of the digits 0-9 that appear in the string,
Trying to write a Java program code for this problem..
Given a string, return the sum of the digits 0-9 that appear in the string, ignoring all other characters. Return 0 if there are no digits in the string. (Note: Character.isDigit(char) tests if a char is one of the chars '0', '1', .. '9'. Integer.parseInt(string) converts a string to an int.)
sumDigits("aa1bc2d3") -> 6
sumDigits("aa11b33") -> 8
sumDigits("Chocolate") -> 0
Use the following method signature:
public int sumDigits(String str) {
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started