Skip to content

Commit a4a63cb

Browse files
authored
Update Sum of Digits (Recursive)
1 parent c751817 commit a4a63cb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Course 2 - Data Structures in JAVA/Recursion Assignment/Sum of Digits (Recursive)

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ Sample Output 2 :
2121
9
2222
*/
2323

24+
public class solution {
25+
26+
public static int sumOfDigits(int input){
27+
// Write your code here
28+
if (input==0)
29+
{
30+
return 0;
31+
}
32+
int smallOutput=sumOfDigits(input/10);
33+
return (input%10)+smallOutput;
34+
}
35+
}

0 commit comments

Comments
 (0)