CJCoding With Joseph
15free / daySign inCreate account

ArrayTools.swap exchanges two elements of an array. It is generic, so one method works for an array of any object type. The header is written. Complete the body.

Requirements: 1. swap(T[] items, int i, int j) exchanges the elements at index i and index j. Nothing else in the array changes. 2. Use a temporary variable of type T to hold one of the two elements while you overwrite its slot. 3. Both indexes are always valid. When i and j are equal the array stays as it was.

Do NOT write a main method.

Expected output

[Cy, Ben, Ana]
[10, 40, 30, 20]

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
GenericsMethods
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.