logo CodeStepByStep logo

reverseFirstK

Language/Type: Java arrays traversals

Write a method named reverseFirstK that accepts an array of integers and an index k as parameters and modifies the first k elements of the array to be in reverse order. For example, if the array a stores {10, -2, 33, 55, 9, 17, 6}, the call of reverseFirstK(a, 5) should reverse the first 5 elements, modifying it to store {9, 55, 33, -2, 10, 17, 6}. If the value of k is 1, 0, negative, or greater than the length of the array, do not modify the array.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.