Well now, this is one of those "it's correct tho" situations. Either the verification is stupid or I am, but yeah I'll let y'all decide that. Please lemme know what's wrong :)
package com.codegym.task.task22.task2202;
import java.util.*;
public class Solution {
public static void main(String[] args) {
System.out.println(getPartOfString("CodeGym is the best place to learn Java."));
}
public static String getPartOfString(String string) {
if (string == null) throw new StringTooShortException();
int start = string.indexOf(" ");
if (start < 0) throw new StringTooShortException();
int end = start;
int count = 0;
while(count < 4){
end = string.indexOf(" ", ++end);
if (end < 0) throw new StringTooShortException(); count++;
}
return string.substring(start, end).trim();
}
public static class StringTooShortException extends RuntimeException{
}
}