java.lang.ArithmeticException: / by zero

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.

java.lang.ArithmeticException: / by zero

Leave a Reply

Your email address will not be published.