Here is the Solved Java Program To Check Whether a Matrix is Sparse Matrix ISC 2021 Computer JAVA.
Checkout:- Java Program to Find Sum of Each Column of Matrix
Checkout:- Sum of Right Diagonal Elements of a Matrix
import java.util.*;
class Sparse_Matrix
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the number of Rows");
int r=sc.nextInt();
System.out.println("Enter the number of Columnns");
int c=sc.nextInt();
int arr[][]=new int[r][c];
System.out.println("Enter the elements of Matrix");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
arr[i][j]=sc.nextInt();
}
}
System.out.println("Input Matrix is:");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println(" ");
}
int size =r*c;
for( int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(arr[i][j]==0)
count++;
}
}
if(count > (size/2))
System.out.println("Given matrix is a Sparse Matrix");
else
System.out.println("Given matrix is not a Sparse Matrix");
}
}
------------
OUTPUT:-
------------
Enter the number of Rows
4
Enter the number of Columnns
4
Enter the elements of Matrix
1
5
98
7
5
3
2
4
8
6
2
1
5
3
9
8
Input Matrix is:
1 5 98 7
5 3 2 4
8 6 2 1
5 3 9 8
Given matrix is not a Sparse Matrix
-----------------------------------
Checkout:- Sum of Left Diagonal Elements of Matrix Java
Checkout:- Mirror Image of Matrix ISC 2013 Practical Java
0 Comments
Just write down your question to get the answer...