Thursday, August 27, 2015

JAVA PROGRAM TO IMPLEMENT THE LINEAR SEARCH

LINEAR SEARCH

import java.io.*;
import java.util.*;
class linear{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n,c,search;
System.out.println("Enter the number");
n=s.nextInt();
int a[]=new int[n];
System.out.println("Enter "+n+" elements");
for(c=0;c<n;c++)
a[c]=s.nextInt();
System.out.println("Enter the search element");
search=s.nextInt();
for(c=0;c<n;c++){
if(a[c]==search){
System.out.println("the element is located at location "+(c+1));
break;
}


}
if(c==n){
System.out.println("the element is not present in the array");
}

}

}

OUTPUT:




No comments:

Post a Comment

Live Traffic

Popular Posts

Designed By RAJESH GOWRABATHUNI