Computer Science, asked by mirfayzanfazu642, 8 months ago

Write a program to perform linear search on given list

[10,51,2,18,4,31,13,5,23,64,29]​

Answers

Answered by abhijatkrishnak
2

Explanation:

go do it u will get it! hope u understood

Attachments:
Answered by anindyaadhikari13
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