package com.javarush.task.task22.task2202;
/*
Найти подстроку
*/
public class Solution {
public static void main(String[] args) {
System.out.println(getPartOfString("Амиго и Диего лучшие друзья! dsa ,ksad asdas"));
}
public static String getPartOfString(String string) {
if(string == null){
throw new TooShortStringException();
}
String finalString = "";
int indexProbel = string.indexOf(" ");
char[] array = string.toCharArray();
int count =0;
int index = 0;
for(int i=0;i<array.length;i++){
if(array[i] == ' '){
count++;
if(count == 4){
finalString = string.substring(indexProbel);
}
if(count==5){
index = i;
finalString = string.substring(indexProbel,index);
}
}
}
if(count<4){
throw new TooShortStringException();
}
return finalString;
}
public static class TooShortStringException extends RuntimeException{
}
}