This will do modular inverse of a matrix coded in java which helps in cryptography in most occasions. And this will works for all matrix sizes.
This is an online calculator for Modular Matrix inverse to test the code. http://planetcalc.com/3324/
This is the application in cryptography http://en.wikipedia.org/wiki/Hill_cipher#Decryption