I can not find the issue solution seems to be ok. Please help.
package pl.codegym.task.task19.task1907;
/*
Liczenie słów
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution {
public static int getCount(String cont) {
int counter = 0;
int index = cont.indexOf("świat");
while (index != -1) {
cont = cont.substring(0, index) + cont.substring(index + 5);
counter++;
index = cont.indexOf("świat");
}
return counter;
}
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
reader.close();
BufferedReader reader1 = new BufferedReader(new FileReader(fileName));
StringBuilder builder = new StringBuilder();
while (reader1.ready()) {
builder.append(reader1.readLine());
}
reader1.close();
System.out.println(getCount(builder.toString()));
}
}