На примерах из условия все правильно выводит, подскажите, что может быть не так?
package com.javarush.task.task22.task2202;
/*
Найти подстроку
*/
public class Solution {
public static void main(String[] args) {
System.out.println(getPartOfString("JavaRush - лучший сервис обучения Java."));
}
public static String getPartOfString(String string) {
if (string == null || string.isEmpty()) throw new TooShortStringException();
int index_1 = string.indexOf(' ');
String[] words = string.split(" ");
if (words.length<5) {
throw new TooShortStringException();
}
int index_5 = 0;
if(words.length > 5){
index_5 = string.lastIndexOf(words[5]);
} else if(words.length == 5){
return string.substring(index_1+1);
}
return string.substring(index_1+1,index_5-1);
}
public static class TooShortStringException extends RuntimeException{
}
}