← Unit 4 · all exercises
Saved in this browser only

Swap the ends

Return a new array like the original but with the first and last items exchanged. An array of one item comes back unchanged.

int[] swapEnds(int[] values)

Solution.java
Loading editor…
Results

Examples

  • java.util.Arrays.toString(Solution.swapEnds(new int[]{1, 2, 3})) → [3, 2, 1]
  • java.util.Arrays.toString(Solution.swapEnds(new int[]{7})) → [7]

There are also 3 hidden tests you can't see. Solve the problem, not the examples.