Linear Search

import java.io.*;
public class LinearSearch
{
public static void main(String[] args)throws IOException
{
int[] arr = new int[5];
int i,n,c=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Elements in Array :-");
for(i=0;i<5;i++)
{
arr[i] = Integer.parseInt(br.readLine());
}
System.out.println("Enter the element to Search :-");
n = Integer.parseInt(br.readLine());

for(i=0;i<5;i++)
{
if(arr[i]==n)
{
c=1;
break;
}
}
if(c==0)
System.out.println("Element Not Found");
else
System.out.println("Element Found");
}
}


/*
Example:
Enter the Elements in Array :-
INPUT:
4
5
2
19
100
Enter the element to Search :-
5
OUTPUT:
Element Found
*/

Comments

Popular Posts