Try not to see the solution before doing it because if you can come up with logic by your own, you will learn a lot. Semaphore; import java. Further Learning. How do we extract 6 out of ? To be frank, calculating sum of digit of an integral number, is not difficult, but I have still seen quite a few programmers fumbles, even after providing hint in terms of division and modules operator.
If you know this property, you can easily solve lots or problems which are related to reversing numbers e.
It's an interesting exercise and you are welcome to find other solution as well. These two techniques are very important and can be used in variety of problem, so always remember these.
There was usual check to solve this problem using both recursion and iteration. In order to calculate the sum of digits, we must get digits as numbers.
You should be able to write this method using both Iteration i. As explained in first paragraph, it does not use any library method instead uses division and modulus operator to calculate sum of digits of a number.
Lock; import java.