Java program to check if it is a sparse matrix