Complete the implementation of method sumOfDigits(int num),
return the sum of its digits recursively. Consider using mod(%)
operator to get the right-most digit in your solution.
Sample runs
Input 1:
Output 1:
Input 2:
Output 2:
Given Code
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
while (stdin.hasNextInt()) {
System.out.println(sumOfDigits(stdin.nextInt()));
}
stdin.close();
}
public static int sumOfDigits(int n) {
// your code starts here
// your code ends here
}
}
Complete the implementation of method sumOfDigits(int num), return the sum of its digits recursively. Consider using mod
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Complete the implementation of method sumOfDigits(int num), return the sum of its digits recursively. Consider using mod
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!