Is my understanding of this While Loop correct?
<p>The example in the book asks the user to enter any positive number. Then the program will add the individual digits separately and print the total. For example if the user enters the number 7512 the program is designed to add 7 + 5 + 1 + 2 and then print the total. </p>

<p>I've written out the way I understand how the code works. Is this correct? Is my understanding of this loop correct with each step, or am I missing any calculations? What happens during the 4th loop when there is no remainder in 7 % 10? </p>

<pre><code>1st  run of loop ... sum = sum + 7512 % 10 which is equal to 2 
                        n = 7512 / 10 which which equals to 751 

2nd run of loop ... sum = 2 + 751 % 10 which is equal to 1 
                         n = 751 / 10  which is equal to 75 

3rd run of loop ...  sum = 3 + 75 % 10 which is equal to 5 
                          n  = 75 / 10 which is equal to 7

4th run of loop ...  sum = 8 + 7 % 10   &lt;------? 
</code></pre>

<hr>

<pre><code>import acm.program.*; 

   public class DigitSum extends ConsoleProgram{

   public void run() {
   println("This program will add the integers in the number you enter.");
   int n = readInt("Enter a positive integer: ");
   int sum = 0;
   while (n &gt; 0) {
        sum += n % 10;
        n /= 10; 
    }
    println("The sum of the digits is" + sum + ".");    
  }
}
</code></pre>
