You are on page 1of 2

Linear Search

============

import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i, n, se, array[];

System.out.print("Enter Number of elements: ");


n = sc.nextInt();
array = new int[n];

System.out.print("Enter the elements in array: ");


for(i=0;i<n;i++){
array[i]=sc.nextInt();
}

System.out.print("Enter the element to find in an array: ");


se=sc.nextInt();

for(i=0;i<n;i++){
if(array[i]==se){
System.out.print("Element "+ se+" is present at the location "+(i+1));
break;
}
if(i==n){
System.out.print("Element "+se+"is not found in the given array");
}
}
}
}

You might also like