91.3k views
1 vote
Write the definition of a method, isReverse, whose two parameters are arrays of integers of equal size. The method returns true if and only if one array is the reverse of the other. ("Reverse" here means same elements but in reverse order.)

User Losbear
by
6.9k points

1 Answer

2 votes

Answer:

public static boolean isReverse(int [ ]a, int [ ]b ){

for (int i=0;i<a.length;i++)

{

if(!(a[i] == b[a.length-i-1]))

return false;

}

return true;

}

Step-by-step explanation:

Using a for loop, we go through the elements of the first array. The if comapres and checks if any of the values are not the same as the appropriate value on the other array, if it is so, then it is not a reverse, and we return false. else we return true.

User Ngn
by
7.3k points