- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.java
More file actions
Latest commit
36 lines (34 loc) · 819 Bytes
/
Copy pathsearch.java
File metadata and controls
36 lines (34 loc) · 819 Bytes
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
importjava.util.*;
classsearch
{
publicstaticvoidmain(Stringargs[])
{
Scannerscan=newScanner(System.in);
intn,i,ele,flag=0;
inta[]=newint[50];
System.out.println("Enter the limit of the array:");
n=scan.nextInt();
for(i=0;i<n;i++)
{
a[i]=scan.nextInt();
}
System.out.println("Enter the element to be searched");
ele=scan.nextInt();
for(i=0;i<n;i++)
{
if(a[i]==ele)
{
flag=1;
break;
}
}
if(flag==1)
{
System.out.println("Element found at position:"+(i+1));
}
else
{
System.out.println("Not found");
}
}
}