2024-08-31 02:05:55 +05:30
|
|
|
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];
|
2024-08-31 09:26:51 +05:30
|
|
|
|
2024-08-31 02:05:55 +05:30
|
|
|
System.out.println("Enter the element to search for:");
|
|
|
|
int searchElement = sc.nextInt();
|
|
|
|
|
2024-08-31 09:26:51 +05:30
|
|
|
System.out.println("Enter the elements of the matrix:");
|
|
|
|
int count = 0;
|
2024-08-31 02:05:55 +05:30
|
|
|
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."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|