java.lang.ArithmeticException: / by zero

The % operator returns the remainder after dividing the first number by the second number. If the second number (in your example size) is zero, then you will get a divide by zero ArithmeticException.

The key is to check if size is zero before performing this loop, and take the appropriate action.

Leave a Comment