-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finding index of a number in an array
- Loading branch information
1 parent
80314b6
commit d9f6804
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import java.util.*; | ||
public class Program | ||
{ | ||
public static void main(String[] args) | ||
{ | ||
Scanner scn=new Scanner(System.in); | ||
int n=scn.nextInt(); | ||
int []arr=new int[n]; | ||
for(int i=0;i<arr.length;i++) | ||
{ | ||
arr[i]=scn.nextInt(); | ||
} | ||
int data=scn.nextInt(); | ||
int index=-1; | ||
//index print hoga agar no data is there then value of result is printed as -1.. | ||
for(int i=0;i<arr.length;i++) | ||
{ | ||
if(data==arr[i]) | ||
{ | ||
index=i; | ||
break; | ||
} | ||
} | ||
System.out.println(index); | ||
} | ||
} |