Hey all.
I have to write a method that accepts 2 arrays and checks if any number in Array_B contains the sum of any subsequent members in Array_A.
1. Does subsequent means that if the array is {1, 3, 4, 5} I should compare:
1+3, 3+4, 4+5
OR :
1+3, 4+5 (in pairs)
2. It is said, assume Array_A is sorted, does that mean it is sorted by size and thus affects the method implementation?
3. Is the method I wrote the best and least complex? (it is forbidden to use interfaces in this assignment).
Any help is most appreciated.
I have to write a method that accepts 2 arrays and checks if any number in Array_B contains the sum of any subsequent members in Array_A.
1. Does subsequent means that if the array is {1, 3, 4, 5} I should compare:
1+3, 3+4, 4+5
OR :
1+3, 4+5 (in pairs)
2. It is said, assume Array_A is sorted, does that mean it is sorted by size and thus affects the method implementation?
3. Is the method I wrote the best and least complex? (it is forbidden to use interfaces in this assignment).
Code:
public static int equal (int a[], int b[])
{
int returnValue = 0;
int sum;
for (int position = 0; position < a.length-1; position++)
{
sum = a[position] + a[position+1];
for (int num = 0; num < b.length; num++)
{
if (sum == b[num])
returnValue = 1;
}
}
return (returnValue);
}
Any help is most appreciated.