Question: public class CountingThrees { /** * Given a non-negative int n, return the count of the occurrences of 3 as a digit, * so for
public class CountingThrees { /** * Given a non-negative int n, return the count of the occurrences of 3 as a digit, * so for example 333 yields 3. (no loops or strings). * Note that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), * while divide (/) by 10 removes the rightmost digit (126 / 10 is 12). * * count3s(303) - 2 * count3s(3) - 1 * count3s(456) - 0 * count3s(37) - 1 * count3s(38) - 1 * * * @param n The value to be checked for 3s * @return int The number of 3s in the number n */ public static int count3s(final int n) { return 0; }// end method }// end class /* Count of 3s - Number: 393 - Count: 2 Count of 3s - Number: 5 - Count: 0 Count of 3s - Number: 3 - Count: 1 Count of 3s - Number: 33333 - Count: 5 Count of 3s - Number: 3453433 - Count: 4 Count of 3s - Number: 30363 - Count: 3 */
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
