← Unit 2 · all exercises
Saved in this browser only

The longer word

Return whichever of the two words is longer. If they are the same length, return the first one.

String longer(String a, String b)

Solution.java
Loading editor…
Results

Examples

  • longer(cat, giraffe) → giraffe
  • longer(elephant, ant) → elephant

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