Sum of Digits of a Number using Recursion – Java Code

Write a java program to find sum of digits of a number using recursion. Given a number, Write a java code to calculate sum of digits of a number using recursion.

For example –

Input number : 123
Output : 6 (1 + 2 + 3)

In my previous tutorial, I have explained how to find sum of digit of a number using iterative approach. In this tutorial, we are  going to learn how we can do it using recursion.

Subscribe Our Tutorials

Get Latest Updates on Facebook

Find Sum of Digits of a Number using Recursion

Find Sum of Digits of a Number using Recursion

Find Sum of Digits of a Number using Recursion – Java Code

To calculate sum of digits of a number recursively. We have written one method (sumOfDigits(int num)) which takes integer as an argument and calculate it’s sum recursively.

For better understanding of this code and how it works i have added video tutorial at the end of this post.

 

In this video tutorial, I have explained how you can write a java code to find sum of digits of a number recursively.

 

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , . Bookmark the permalink.