Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Java/Algorithms/Arrays/arraysearch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class LinearSearchExample{
public static int linearSearch(int[] arr, int key){
//searching element in an array
for(int i=0;i<arr.length;i++){
if(arr[i] == key){
return i;
}
}
return -1; // if element not found
}
public static void main(String a[]){
int[] a1= {10,20,30,50,70,90}; // user defined array
int key = 50;
System.out.println(key+" is found at index: "+linearSearch(a1, key));
}
}