- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathelementSearch.java
More file actions
Latest commit
43 lines (43 loc) · 692 Bytes
/
Copy pathelementSearch.java
File metadata and controls
43 lines (43 loc) · 692 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
37
38
39
40
41
42
43
importjava.util.Scanner;
classArray
{
Scannersc = newScanner(System.in);
intn,t,arr[];
publicvoidinput()
{
n = sc.nextInt();
arr = newint[n];
for(inti=0;i<n;i++)
{
arr[i] = sc.nextInt();
}
}
publicvoidsearch()
{
t=0;
System.out.println("Enter a no. to search");
intnum = sc.nextInt();
for(inti=0;i<n;i++)
{
if(num==arr[i])
t=i;
}
}
publicvoidshow()
{
if(t==0)
System.out.println("-1");
else
System.out.println("Found at index " + t);
}
}
classelementSearch
{
publicstaticvoidmain(Stringargs[])
{
Arrayobj = newArray();
obj.input();
obj.search();
obj.show();
}
}