Write a function solution that accepts a sorted array of numbers a, size of the array n and the element to search
e. the function should return the index of the element.
Answers
Answered by
0
import java.util.*;
class array
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of array");
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<a.length;i++)
{
System.out.println("Enter the elements:");
a[i]=sc.nextInt();
}
System.out.println("Enter the element to search:");
int search=sc.nextInt();
for(i=0;i<a.length;i++)
{
if(a[i]==search)
{
System.out.print(i);
break;
}
}
}
class array
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of array");
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<a.length;i++)
{
System.out.println("Enter the elements:");
a[i]=sc.nextInt();
}
System.out.println("Enter the element to search:");
int search=sc.nextInt();
for(i=0;i<a.length;i++)
{
if(a[i]==search)
{
System.out.print(i);
break;
}
}
}
Similar questions
Physics,
7 months ago
Social Sciences,
7 months ago
Science,
7 months ago
English,
1 year ago
Chemistry,
1 year ago