Given a matrix and we have to check whether it is sparse matrix or not using java program.
Sparse Matrix
A matrix in which most of the elements are '0' then it is said to be a sparse matrix. Sparse matrices are used in specific ways in computer science and have different storage and techniques related to their use.
Example-1
Input Matrix
1 1 1
0 0 0
1 1 1
Output: It's not a sparse matrix
Example-2
Input Matrix
1 0 0 1
0 1 0 1
0 1 0 1
0 0 0 1
Output: It's a sparse matrix
Program to check sparse matrix in Java
Output 1
Output 2