Write a method named repeatedSequence
that accepts two arrays of integers a1 and a2 as parameters and returns true
if a2 is composed entirely of repetitions of a1 and false
otherwise.
For example, if a1 stores the elements {2, 1, 3}
and a2 stores the elements {2, 1, 3, 2, 1, 3, 2, 1, 3}
, the method would return true
.
If the length of a2 is not a multiple of the length of a1, your method should return false
.
You may assume that both arrays passed to your method will have a length of at least 1.
The following table shows some calls to your method and their expected results:
Arrays |
Returned Value |
int[] a1 = {2, 1};
int[] a2 = {2, 1, 2, 1, 2, 1};
|
repeatedSequence(a1, a2) returns true
|
int[] a3 = {2, 1, 3};
int[] a4 = {2, 1, 3, 2, 1, 3, 2};
|
repeatedSequence(a3, a4) returns false
|
int[] a5 = {23};
int[] a6 = {23, 23, 23, 23};
|
repeatedSequence(a5, a6) returns true
|
int[] a7 = {5, 6, 7, 8};
int[] a8 = {5, 6, 7, 8};
|
repeatedSequence(a7, a8) returns true
|
int[] a9 = {5, 6};
int[] a0 = {5, 6, 7, 5, 6, 5};
|
repeatedSequence(a9, a0) returns false
|
For full credit, do not modify the elements of the arrays passed in.