Question: Part B [Sum the digits in an integer]Write a method with the following header that computes the sum of the digits of an integer :
Part B [Sum the digits in an integer]Write a method with the following header that computes the sum of the digits of an integer : public static int sumDigits (int num) For example, sumDigits (2371) returns 13 (which is the sum 2+3+7+1) Use % operation to extract last digit, and / operation to remove the last digit (e.g. 2371 % 10 gives you 1, and 2371/10 gives you 237). Hint: one of the participation activity did this operation in a loop until all digits are extracted. Implement and test the method for various input values.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
