Respuesta :
Answer:
public static void main()
{
Scanner console = new Scanner(System.in);
System.out.println("Enter in a value");
int a = console.nextInt();
int[] array = {1,2,3,4,5};
int a1 = search(array, a);
System.out.println(a1);
}
public static int search(int[] array, int value)
{
boolean okay = true;
int b = 0;
for(b = 0; b<=array.length-1; b++)
{
if(value==array[0])
{
okay=true;
}
else
{
okay = false;
}
}
if(okay = true)
{
return b;
}
else
{
return -1;
}
}
Explanation:
Answer:
Answer is in the attached screenshot!
Explanation:
Just iterate through the values in the list - if the value at the index is equal to the one you are searching for, just return that index. If no value is returned then return with -1!
