code should be in java! Thank you! This method reverses the subsection of the pa
ID: 3709983 • Letter: C
Question
code should be in java!
Thank you!
This method reverses the subsection of the passed array defined by index1 and index2. index2 is non-inclusive and will not be swapped with index1. If *index1index2 then the two indexes will be swapped before they are checked for validity. eparam arr -the array to reverse eparam index1-the first index of the subsection eparam index2 -the non-inclusive upper bound of the subsection, " last element swapped wil1 be at the index Cindex2-1) ethrows IndexOutOfBoundsException if index1 or (index2-1) are not valid indexes of arc se public void reverseWindow(int[] arr, int start, int end) throws IndexOutOfBoundsExceptionExplanation / Answer
public class ReverseWindow { public void reverseWindow(int[] arr, int start, int end) throws IndexOutOfBoundsException { end--; if(start > end) { int temp = start; start = end; end = temp; } if(start < 0 || end < 0 || start >= arr.length || end >= arr.length) { throw new IndexOutOfBoundsException(); } int temp; while (startRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.