Can You explain how it works? : It would be awesome if someone could give me a proper explanation of the code :)

Code is working and I like it, however as I am learning Java, need to understand every bit of it.

Thanks!

Checked StringBuilder() - seems fine,
However part inside the loop is not quite clear.



public class SquareDigit {

public int squareDigits(int n) {
       StringBuilder builder = new StringBuilder();

       while(n > 0) {
           int digit = n % 10;

           int square = digit * digit;
           builder.insert(0, square);

           n = Math.floorDiv(n, 10);
       }

       return Integer.valueOf(builder.toString());
 }
 }