Skip to content

Commit 569f707

Browse files
author
codehouseindia
authored
Merge pull request codehouseindia#119 from Meghraj2520/patch-2
linear search in java .
2 parents 2037019 + 835099c commit 569f707

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

linear search in java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class LinearSearchExample{
2+
public static int linearSearch(int[] arr, int key){
3+
for(int i=0;i<arr.length;i++){
4+
if(arr[i] == key){
5+
return i;
6+
}
7+
}
8+
return -1;
9+
}
10+
public static void main(String a[]){
11+
int[] a1= {10,20,30,50,70,90};
12+
int key = 50;
13+
System.out.println(key+" is found at index: "+linearSearch(a1, key));
14+
}
15+
}

0 commit comments

Comments
 (0)