program for linear search in java
Answers
Answered by
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");
}
}
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
Answered by
2
hiiiii friend
here is your answer
see the attached file ⬆ ⬆ ⬆
glad to help you
hope it helps
thank you.
here is your answer
see the attached file ⬆ ⬆ ⬆
glad to help you
hope it helps
thank you.
Attachments:
Similar questions