Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 63f5867

Browse files
Create search_element.java
1 parent 234ffc8 commit 63f5867

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎search_element.java‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /