-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_an_element.java
50 lines (37 loc) · 1.12 KB
/
search_an_element.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
38
39
40
41
42
43
44
45
46
47
48
49
50
//{ Driver Code Starts
import java.util.*;
import java.io.*;
import java.lang.*;
class Main
{
public static void main(String args[])throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while(t-- > 0)
{
int sizeOfArray = Integer.parseInt(read.readLine());
int arr[] = new int[sizeOfArray];
String st[] = read.readLine().trim().split("\\s+");
for(int i = 0; i < sizeOfArray; i++)
arr[i] = Integer.parseInt(st[i]);
int x = Integer.parseInt(read.readLine());
Solution obj = new Solution();
System.out.println(obj.search(arr, sizeOfArray, x));
}
}
}
// } Driver Code Ends
class Solution{
static int search(int arr[], int N, int X)
{
// Your code here
int flag=0;
for(int i=0;i<N;i++)
{
if(arr[i]==X)
return i;
}
return -1;
}
}