выводит все верно, что валику опять не так то?))
package com.javarush.task.task22.task2202;
/*
Найти подстроку
*/
public class Solution {
public static void main(String[] args) {
System.out.println(getPartOfString("JavaRush - лучший сервис обучения Java."));
}
public static String getPartOfString(String string) {
try{
char[] arr = string.toCharArray();
char space = ' ';
int counterspaces = 0;
int index1 = 0;
int index2 = arr.length-1;
for (int x=0;x<arr.length;x++){
if (arr[x] == space) {counterspaces++;
if (counterspaces == 1) index1=x+1;
if (counterspaces == 5) index2=x;}
}
if (counterspaces<4) throw new TooShortStringException();
String s = string.substring(index1,index2);
return s;}
catch (Exception e) {
throw new TooShortStringException();
}
}
public static class TooShortStringException extends RuntimeException{
}
}