JAVA PROGRAM FOR LINEAR SEARCH
import java.io.*; class Search { public static void main(String args[ ])throws IOException { BufferedRea...

https://www.computersprofessor.com/2016/06/java-program-for-linear-search.html
import java.io.*;
class Search
{
public static void
main(String args[ ])throws IOException
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("ENTER N VALUE");
int n=Integer.parseInt(br.readLine( ));
int a[ ]=new int[n];
for (int i=0;i
{
System.out.println("ENTER
ELEMENT");
a[i]=Integer.parseInt(br.readLine(
));
}
int found=0;
System.out.println("ENTER KEY
VALUE");
int key=Integer.parseInt(br.readLine());
for(int i=0;i
{
if(key==a[i])
{
found=1;
System.out.println("KEY IS FOUND AT"+i);
break;
}
}
if(found==0)
{
System.out.println("KEY IS NOT FOUND");
}
}
}
OUTPUT:
ENTER N VALUE
5
ENTER ELEMENT
1
ENTER ELEMENT
2
ENTER ELEMENT
3
ENTER ELEMENT
4
ENTER ELEMENT
5
ENTER KEY VALUE
4
KEY IS FOUND AT 3