Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me to solve this code check /** * PQ07 Sample Problem. * @author * @version */ public class PQ07S { /** * Write

Please help me to solve this code check

/** * PQ07 Sample Problem. * @author * @version */ public class PQ07S { /** * Write the method sumDigits(). * * The method has one input, a String str, and * returns the sum of the digit characters in the * String. A digit is in the interval [0..9]. You * can convert a digit to an integer by subtracting * '0' (notice this is the char value '0', not "0" or 0). * However, if a digit is a 7, it counts as a 2. * Use a for loop, the charAt() and length() String * methods and if statements. Do not use any other * methods, such as Integer.parseInt() or * Character.isDigit(). If there are no digit characters * in the String, return 0. * * Examples: * sumDigits("aa1bc2d3") returns 6 * sumDigits("aa11b33") returns 8 * sumDigits("Chocolate") returns 0 * * @param str the string to process. * @return the numeric sum as described above. */ // TODO - Write the sumDigits method here.

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions