Output seems to be good
package com.codegym.task.task19.task1907;
/*
Counting words
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String a = br.readLine();
br.close();
FileReader fr = new FileReader(a);
BufferedReader br1 = new BufferedReader(fr);
ArrayList<String> list = new ArrayList<>();
while(br1.ready()){
String[] ss = br.readLine().split("\\p{Punct}");
Collections.addAll(list, ss);
}
fr.close();
br1.close();
int num=0;
for(int i = 0; i<list.size(); i++){
if(list.get(i).equals("world")){
num++;
}
}
System.out.println(num);
}
}