Write a recursive method sumOfDigits(int n) that takes a positive integer n and returns the sum of its digits. Example: sumOfDigits(123); // Output: 6 (1 + 2 + 3)sumOfDigits(9876); // Output: 30 (9 + 8 + 7 + 6) Rubric: Recursive Sum of Digits Method (10 points) Criteria Full Marks (2-3 pts) Partial Marks (1-2 pts) No Marks (0 pts) Method Signature (2 pts) Correct signature (int sumOfDigits(int n)). Minor issues in method signature (e.g., incorrect return type). Missing or incorrect signature. Base and Recursive Case (4 pts) Correctly implements base case (n < 10) and recursive step (n % 10 + sumOfDigits(n / 10)). Base case correct, but recursion has minor logic errors. Does not implement recursion correctly or uses loops instead. Correctness of Output (2 pts) Returns the correct sum for any positive integer. Returns correct sum for simple cases but has edge case issues. Incorrect output for most cases. Code Style and Readability (2 pts) Clean code, meaningful variable names, and proper formatting. Some formatting issues or confusing variable names. Code is messy, lacks indentation, or is missing.
Category: Uncategorized
Which of the following is an acceptable steam sterilization…
Which of the following is an acceptable steam sterilization material?
My [BLANK-1] is a what?
My [BLANK-1] is a what?
Which tool will enable you to view your AWS costs associated…
Which tool will enable you to view your AWS costs associated with the EC2 service from 6 months ago?
According to Laplace’s Law, a larger alveoli compared to a s…
According to Laplace’s Law, a larger alveoli compared to a smaller alveoli would:I. Expand easierII. Have greater pressureIII. Have a lower surface tensionIV. Decrese in radius
A comparison of profit and expense items in the income state…
A comparison of profit and expense items in the income statement expressed as a percentage of sle income
A document designed to communicate the organization’s goals…
A document designed to communicate the organization’s goals for the future
The difference between gross profit and expenses when gross…
The difference between gross profit and expenses when gross profit is larger
What animal moo’s?
What animal moo’s?
A respiratory therapist has been attempting to wean a patien…
A respiratory therapist has been attempting to wean a patient off of ventilatory support but fails when placed on a spontaneous mode. The patient’s vital capacity and negative inspiratory force has been inadequate. What laboratory data should the therapist assess next?