На моей тестовой строке:
bigworld, world, "world", world! :world, -world, +world? world5 middleworld, worlds.
"binary world".
"The world population is the sum of all human populations at any time; similarly, the world economy is the sum of the economies of all societies or countries, especially in the context of globalization. Terms such as "world championship", "gross world product", and "world flags" imply the sum or combination of all sovereign states."
находит 12 слов. Вроде бы верно, но не проходит по последнему пункту.
package com.javarush.task.task19.task1907;
/*
Считаем слово
*/
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 void main(String[] args) {
String inputFile = "";
StringBuffer editStr = new StringBuffer();
int counter = 0;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
inputFile = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
try (FileReader fileReader = new FileReader(inputFile)) {
while (fileReader.ready()) {
editStr.append((char)fileReader.read());
}
} catch (Exception e) {
e.printStackTrace();
}
Matcher matcher = Pattern.compile("\\W\\world\\W").matcher(editStr.toString());
while (matcher.find()) {
counter++;
}
System.out.println(counter);
}
}