I would say the problem is not well-defined. For example, what if the string was "hello.hello1.hello2.jpg.hello3"? What if it was "hello.hello1.hello2"? What if it were "JPG"?
Simply providing one example does NOT define the problem.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rob Spoor wrote:And what does lastIndexOf return if there is not dot in the String? And what will that specific return value do with the calls to substring?
First check for indexOf(".") if it returns true then check for LastIndexOf(".")