I am trying to write a program that checks if there is a sequence in an array using Recursion {2,4,6,8} would return true while (2,4,6,5} would return false. This is what I have so far... TIA
private static boolean arrPattern(int[] arr)
{
int sequence =arr[1]- arr[0];
for (int i=1;i<arr.length;i++)
for(int j=2;j<arr.length;j++)
{
if (sequence == (arr[j]- arr[i]) & arr.length>0)
{
send the subarray (recursive)
}
else if (j-i !=sequence)
return false;
else
return true;
}
}
As you can tell I am not sure how to send a subarray to the method again. I believe I have the basic idea down just need to figure out that last part.
I know you can do this simply with having a arraylist instead of a simple array but I want to use an array to solve this.