← Unit 4 · all exercises
Saved in this browser only

First plus last

Return the first item added to the last. The array always has at least one item; with exactly one, that item counts twice.

int firstPlusLast(int[] values)

Solution.java
Loading editor…
Results

Examples

  • Solution.firstPlusLast(new int[]{1, 2, 3}) → 4
  • Solution.firstPlusLast(new int[]{5}) → 10

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