← Unit 1 · all exercises
Saved in this browser only

Where does it appear

Return the position where the search text first appears inside the sentence. Counting starts at 0. If it is not there at all, return -1 — which is what indexOf already does.

int positionOf(String sentence, String search)

Solution.java
Loading editor…
Results

Examples

  • positionOf(hello world, world) → 6
  • positionOf(hello, h) → 0

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