Skip to content

Commit

Permalink
finding index of a number in an array
Browse files Browse the repository at this point in the history
  • Loading branch information
suhanigupta23 authored Feb 5, 2024
1 parent 80314b6 commit d9f6804
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions finding_index_of_a_number_in_an_array.java
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);
}
}

0 comments on commit d9f6804

Please sign in to comment.