add a bigInteger value to a 2d array

For those with a maths background it is a surprising feature that

 System.out.println("=" + (-3 % 4));

for example, returns -3 instead of 1 (which would be in the range [0,3]);

Edit:

in other words, the error message

error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -8

is ultimately caused by (n % m) can return negative values. A statement like

num=(26+num)%26;

would cure it.

Leave a Comment