-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoDArray.java
37 lines (34 loc) · 1.14 KB
/
TwoDArray.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
34
35
36
37
import java.util.Scanner;
public class TwoDArray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter rows and columns..");
int rows = sc.nextInt();
int cols = sc.nextInt();
int matric[][] = new int[rows][cols];
//Input
System.out.println("Entering matric elements..");
for(int i=0; i<rows; i++){
for(int j=0; j<cols; j++){
matric[i][j]=sc.nextInt();
}
}
// Output
// System.out.println("Showing output...");
// for(int i=0; i<rows; i++){
// for(int j=0; j<cols; j++){
// System.out.print(matric[i][j]+" ");
// }
// System.out.println();
// }
System.out.println("Enter the key...");
int x = sc.nextInt();
for(int i=0; i<rows; i++){
for(int j=0; j<cols; j++){
if(matric[i][j] == x){
System.out.println("Element found at location ( "+i+", "+j+" )");
}
}
}
}
}