Добавил вроде все советы что были на форуме, но все равно валидатор не пускает
package com.javarush.task.task22.task2202;
/*
Найти подстроку
*/
public class Solution {
public static void main(String[] args){
System.out.println(getPartOfString("Амиго и Диего лучшие друзья!"));
System.out.println(getPartOfString("Моя задача не работает, как требует условие"));
//System.out.println(getPartOfString("Тесты для слабаков"));
System.out.println(getPartOfString("День числа пи — неофициальный праздник, который отмечается любителями математики 14 марта в 1:59:26 в честь математической константы — числа пи."));
System.out.println(getPartOfString("День был отмечен в 1988 году в научно-популярном музее Эксплораториум"));
}
public static String getPartOfString(String string) throws TooShortStringException {
if (string == null || string.isEmpty())
throw new TooShortStringException();
int startIndx,tempIndex, endIndex;
startIndx = string.indexOf(" ");
if (startIndx==-1) throw new TooShortStringException();
//System.out.println(startIndx);
tempIndex = startIndx;
for (int i = 0; i<3; i++){
tempIndex = string.indexOf(" ",tempIndex+1);
if (tempIndex==-1) throw new TooShortStringException();
}
endIndex = string.indexOf(" ",tempIndex+1);
if (endIndex==(-1)){
return string.substring(startIndx);
}
return string.substring(startIndx,endIndex);
}
public static class TooShortStringException extends RuntimeException {
}
}