We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 234ffc8 commit 63f5867Copy full SHA for 63f5867
search_element.java
@@ -0,0 +1,28 @@
1
+import java.util.Scanner;
2
+public class Main
3
+{
4
+ public static void main(String[] args)
5
+ {
6
+ int n;
7
+ System.out.println("Enter number of elements:");
8
+ Scanner in=new Scanner(System.in);
9
+ n=in.nextInt();
10
+ int[] arr=new int[n];
11
+ for(int i=0;i<n;i++)
12
13
+ arr[i]=in.nextInt();
14
+ }
15
+ System.out.print("Enter the Search element:");
16
+ int element=in.nextInt();
17
+ int index=-1;
18
+ for(int i=0;i<=n;i++)
19
20
+ if(arr[i]==element)
21
22
+ index=i;
23
+ break;
24
25
26
+ System.out.print(index);
27
28
+}
0 commit comments