Пытался решить уже тремя способами. Пытаюсь победить уже второй день из принципа. Помогите, что не так.
package com.javarush.task.task19.task1907;
import java.io.*;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution{
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedReader reader1= new BufferedReader(new FileReader(reader.readLine()));
reader.close();
String s="";
String data="";
while ((data = reader1.readLine())!=null){
s=s+data;
}
reader1.close();
int result=0;
int count=0;
/*
String[] stringArray= s.split("[,.:;#@$&_+=)(':%/*,.!?\\r\\n] ");
for(String qq:stringArray){
if (qq.equals("world")) result++;
}
for (int i = 0; i <s.length() ; i++) {
int a = s.indexOf("world",count);
if (a>=count){
result++;
count=a+1;}
}
*/
Pattern pattern = Pattern.compile("\\p{Punct}world\\p{Punct}");
Matcher matcher = pattern.matcher(s);
if(matcher.find())
result++;
System.out.println(result);
}
}