0% found this document useful (0 votes)
3 views1 page

Java Linear Search Example Code

The document presents a Java class named LinearSearchExample that implements a linear search algorithm to find the index of a specified key in an array. It contains a method called LinearSearch that returns the index of the key if found, or -1 if not. The main method initializes an array and searches for a key, printing the result to the console.

Uploaded by

NATHIYA T
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Java Linear Search Example Code

The document presents a Java class named LinearSearchExample that implements a linear search algorithm to find the index of a specified key in an array. It contains a method called LinearSearch that returns the index of the key if found, or -1 if not. The main method initializes an array and searches for a key, printing the result to the console.

Uploaded by

NATHIYA T
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Public class LinearSearchExample {

public static int LinearSearch(int [] arr, int key){


for(int i=0;i<[Link];i++){
if(arr[i]==key){
return i;
}
}
return-1;
}
Public Static void main.(Strings(args[]){
int [] al={10,20,30,40,50,70,90}:
int key=50;
[Link](key="is foundatindex:"+linersearch(al,key));
}
}

You might also like