Updating matrix problem in java