Untitled

mail@pastecode.io avatar
unknown
plain_text
12 days ago
700 B
1
Indexable
Never
package Search;
import java.util.*;
public class LinearSearchGeneralised {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		System.out.println("Enter size of array: ");
		int n= sc.nextInt();
		int array[]= new int [n];
		int j;
		for(int i=0;i<n;i++) {
		System.out.println("Enter array element ");
		array[i]=sc.nextInt();
		}
		System.out.println("Enter element to find from array: ");
		int key=sc.nextInt();
		int f=0;
		for(j=0;j<n;j++) {
			if(array[j]==key) {
				System.out.println("Element found at: "+ (j+1));
				f=1;
				break;
				
			}
		

}
		sc.close();
		if(f==0) {
			System.out.println("Element not found");
		}
}
}
Leave a Comment