Untitled
Never
import java.util.Scanner; class Matrix { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter size of matrix"); int m = sc.nextInt(); int n = sc.nextInt(); double[][] matrix = new double[m][n]; int zeroCount = 0; System.out.println("Enter the elements of the matrix"); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { matrix[i][j] = sc.nextDouble(); if (matrix[i][j] == 0) { zeroCount++; } } } if (zeroCount > (m * n) / 2) { System.out.println("It is a sparse matrix"); } else { System.out.println("It is not a sparse matrix"); } } }