Ask Question
13 November, 00:51

Write the definition of a method, oddsMatchEvens, whose two parameters are arrays of integers of equal size. The size of each array is an even number. The method returns true if and only if the even-indexed elements of the first array equal the odd-indexed elements of the second, in sequence. That is if w is the first array and q the second array, w[0] equals q[1], and w[2] equals q[3], and so on.

+4
Answers (1)
  1. 13 November, 03:27
    0
    public boolean oddsMatchEvens (int[ ] w, int[ ] q) {

    for (int i = 0; i < w. length-1; i+=2) {

    if (w[i]! = q[i + 1])

    return false;

    else

    continue;

    }

    return true;

    }

    Explanation:

    Since it was mentioned that both arrays are of equal length, we use the length of the first array minus one as our condition in order check the last item. Then, we have to check first array even with second array odd so we increment by be i+=2 and not the popular i++. The continue statement ensures that as soon as only one case fails, the loop with stop and return true.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the definition of a method, oddsMatchEvens, whose two parameters are arrays of integers of equal size. The size of each array is an ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers