Question: Java Write a recursive Boolean method named isMember. The method should search an array for a specified value, and return true if the value is
Java
Write a recursive Boolean method named isMember. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in the array.
This is the main method that sets up the problem and calls the isMember() method. The solution must be a RECURSIVE SEARCH, not a linear search.
public static void main(String[] args)
{
// Make an array.
final int ARRAY_SIZE = 10;
int[] numbers = {2, 4, 16, 20, 14, 12, 10, 6 ,18, 8 };
// Test all of the values from 0 through 20 and see if
// they are in the array.
for (int x = 0; x <= 20; x++)
{
if (isMember(numbers, x, ARRAY_SIZE))
System.out.println(x + " is found in the array.");
else
System.out.println(x + " is not found in the array.");
}
}
Output 1
0 is not found in the array
1 is not found in the array
2 is found in the array.
3 is not found in the array
4 is found in the array
...
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
