Not able to know what is going wrong. i tried many possibilites but it passes all. @codegym, could you help me with the test cases you are testing with to know the root cause.?
package com.codegym.task.task19.task1907;
import java.io.*;
import java.nio.Buffer;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String file1 = br.readLine();
FileReader reader = new FileReader(file1);
String wordList="";
while(reader.ready()){
char data = (char) reader.read();
String dataString=Character.toString(data);
//this mean replace all punctuation to space and split by space, write all words into array.
wordList += dataString.replaceAll("[^a-zA-Z]", "");
}
// System.out.println(wordList);
int count=0;
wordList=wordList.replaceAll("world","=");
char charList[]=wordList.toCharArray();
for(int i=0;i<charList.length;i++){
if(Character.toString(charList[i]).equals("=")){
count++;
}
}
br.close();
reader.close();
System.out.println(count);
}
}