Write a program to perform linear search on given list
[10,51,2,18,4,31,13,5,23,64,29]
Answers
Answered by
2
Explanation:
go do it u will get it! hope u understood
Attachments:
![](https://hi-static.z-dn.net/files/d7e/cc3700a024a7ee778efa79c66090075f.jpg)
Answered by
1
Question:-
Write a program to perform linear search on the given list.
[10,51,2,18,4,31,13,5,23,64,29]
Program:-
import java.util.*;
class X
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[]=[10,51,2,18,4,31,13,5,23,64,29];
System.out.print("Enter the number to be searched: ");
boolean found=false;
int x=sc.nextInt();
for(int i=0;i<a.length;i++)
{
if(a[i]==x)
{
System.out.println("Found at position "+i);
found=true;
break;
}
}
if(!found)
System.out.println("Not found in the list.");
}
}
Similar questions