Java program for sum of digits of number

In this post, we will see how to find sum of digits of number in java.
You can find unit’s place digit by number%10, add it to the total and divide the number by 10 to remove the unit’s place.

Output:

Enter a Number : 5385
Sum of digits of number 5385 is 21

That’s all about Java program to add digits of number.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *