Requirements 3 and 4 are not validating...
package com.codegym.task.task22.task2202;
/*
Find a substring
*/
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();
String[] words = string.split(" ");
int start = string.indexOf(words[1]);
if (words.length < 5) throw new StringTooShortException();
int end = string.indexOf(" " + words[5]);
return string.substring(start, end);
}
public static class StringTooShortException extends RuntimeException {
}
}