import java.util.Scanner; class SearchCount { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println( "Enter the number of rows and columns in the matrix: " ); int m = sc.nextInt(); int n = sc.nextInt(); int[][] matrix = new int[m][n]; System.out.println("Enter the elements of the matrix:"); int count = 0; System.out.println("Enter the element to search for:"); int searchElement = sc.nextInt(); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { int element = sc.nextInt(); matrix[i][j] = element; if (element == searchElement) { count++; } } } System.out.println( "The element " + searchElement + " occurs " + count + " times in the matrix." ); } }