Program To Check Whether a Matrix is Sparse Matrix

JAVA Program to determine whether a given matrix is a Sparse matrix 2021 - ISC Solved Program

JAVA Program To Check Whether a Matrix is Sparse Matrix 2021

Here is  the Solved Java Program To Check Whether a  Matrix is Sparse Matrix  ISC 2021 Computer JAVA.

We are uploading these types of program. However, if you need fully compiled solution of any type of Java program then simply leave a comment below, we will help you at the earliest. 😊😊
 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 

Post a Comment

0 Comments