Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the code of Linear Search suing Java #184

Merged
Merged
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
18 changes: 18 additions & 0 deletions linear_search/linear_search.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class linear_search{

// Function for Linear Search
public static int linearSearch(int[] arr, int key){
for(int i=0;i<arr.length;i++){
if(arr[i] == key){
return i;
}
}
return -1;
}
public static void main(String a[]){
// Sample Array
int[] a1= {10,20,30,40,50,60};
int key = 30;
System.out.println(key+" is found at index: " + linearSearch(a1, key));
}
}