Skip to content
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
27 changes: 27 additions & 0 deletions Java/Linear_search.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.util.*;
public class linearsearch{
public static int lisearch(int key,int numbers[]){
for(int i=0; i<=numbers.length ;i++){
if (numbers[i]==key){
return i;
}

}

return -1;
}

public static void main(String args[]){
int numbers[] ={2,4,6,8,10,12,14,16};
Scanner s = new Scanner(System.in);
System.out.println("enter the key:");
int key = s.nextInt();
int index = lisearch(key , numbers);
if(index==-1){
System.out.println("index not found");
}
else{
System.out.println("index at key " + key +" is : " + index);
}
}
}