Ругается как будто я лишнее вывожу, а я в упор не вижу😢. Вроде всё так. подскажите что не так?
Убедись, что программа выводит только одно целое число, и никаких лишних надписей - говорили они!!!😀
package com.javarush.task.task19.task1907;
import java.io.*;
import java.util.Scanner;
import java.util.regex.Pattern;
/*
Считаем слово
*/
public class Solution {
public static void main(String[] args) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int counter = 0;
try (BufferedReader reader = new BufferedReader(new FileReader(bufferedReader.readLine()));) {
while (reader.ready()) {
String s = reader.readLine();
if (s.equals("world"))
counter++;
if (s.startsWith("world")&& s.length()>5){
String chek = s.substring(5, 6);
if (Pattern.matches("[\\p{Punct}\\p{IsPunctuation}]",chek)){
counter++;
s = s.substring(5);}
}
while (s.contains(" world")){
int index = s.indexOf(" world");
String chek1 = s.substring(index+6, index+7);
if (Pattern.matches("[\\p{Punct}\\p{IsPunctuation}]",chek1)){
counter++; }
s = s.substring(index+7);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.print(counter);
}
}