The java program is for iterative linear search with static values as input. Linear Search using java code is written for simple understanding.
class LinearSearchExample
{
static Object[] a = { 21, 36, 81, 117, 50, 43, 26, 99 };
static Object key = 81;
public static void main(String args[])
{
if( lSearch() )
System.out.println(key + " found in the list");
else
System.out.println(key + " not found in the list");
}
static boolean lSearch()
{
for( int i=0; i<a.length; i++)
if(key == a[i]) return true;
return false;
}
}
Check the other code written in C language. C Program to find an Element using Linear Search
OUTPUT:
81 found in the list