Skip to content

Commit 39488a9

Browse files
Merge pull request #83 from mohdraheez/patch-1
Create linearsearch.java
2 parents bad71df + 454e357 commit 39488a9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Linearsearch.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)