and why doesnt it?
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) {
String s = null;
String res = null;
String[] array = string.split("\\s+");
if(array.length < 5 || string == null) throw new StringTooShortException();
else{
StringBuilder str = new StringBuilder();
for(int i = 1; i < 5; i++){
str.append(array[i] + " ");
}
res = str.toString();
}
return res.trim();
}
public static class StringTooShortException extends RuntimeException {
}
}