Computer Science, asked by shishir38, 1 year ago

program for linear search in java

Answers

Answered by UnknownDude
7
import java.util.*;
class LinearSearch
{
public static void main()
{
int arr[]=new int[10],c=0;
Scanner in=new Scanner(System.in);
for(int i=0;i<10;i++)
{
System.out.println("Enter a number");
arr[i]=in.nextInt();
}
System.out.println("Enter number to be searched");
int n=in.nextInt();
for(int i=0;i<10;i++)
{
if(arr[i]==n)
c++;
}
if(c==1)
System.out.println("Search successful");
else
System.out.println("Search unsuccessful");
}
}

Pallavi441: srry
Pallavi441: this message is not for u
Pallavi441: very srry
shishir38: ok
shishir38: ur answer couldn't be seen
shishir38: bt thanx fr the help
shishir38: thanks unknown dude
PRITHVIRAJ25: hey man...ur "enter 10 nos"could have been outside the loop so as to print it only once and thentake the inputs
Answered by adarshhoax
2
hiiiii friend
here is your answer

see the attached file ⬆ ⬆ ⬆

glad to help you
hope it helps
thank you.
Attachments:
Similar questions