forked from BimalRajGyawali/hacktoberfest-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoDArraySearch.java
34 lines (33 loc) · 895 Bytes
/
TwoDArraySearch.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
import java.util.*;
class TwoDArraySearch
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the rows");
int r=sc.nextInt();
System.out.println("Enter the columns");
int c=sc.nextInt();
int numbers[][]=new int[r][c];
System.out.println("Enter the elements");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
numbers[i][j]=sc.nextInt();
}
}
System.out.println("Enter the number you want to search");
int x=sc.nextInt();
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(numbers[i][j]==x)
{
System.out.println(x+" found at position "+(i+1)+","+(j+1));
}
}
}
}
}