-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchxmat.java
33 lines (32 loc) · 984 Bytes
/
searchxmat.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// search for element x in the matrix
import java.util.*;
public class searchxmat {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
int col =sc.nextInt();
int[][] mat= new int [row][col];
for(int i=0; i<row; i++){
for(int j=0; j<col; j++){
mat[i][j]= sc.nextInt();
}
}
// for(int i=0; i<row; i++){
// for(int j=0; j<col; j++){
// System.out.print(x[i][j]+ " ");
// }
// System.out.println();
// }
int x= sc.nextInt();
for(int i=0; i<row; i++){
for(int j=0; j<col; j++){
if(mat[i][j] == x){
System.out.print("X found at position" + " " + i + " " + j);
}
// else{
// System.out.print("X not found :(");
// }
}
}
}
}