and fail at the last step...
for exemple, my code count worldworld for 2 occurrence..
what means "punctuation signs" ? everything else then Character.isLetter ?
french error : "Détermine pourquoi le programme a trouvé plus d'occurrences du mot « world » qu'il en existe dans le fichier."
package fr.codegym.task.task19.task1907;
/*
Comptage des mots
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
String filename = console.readLine();
FileReader file = new FileReader(filename);
StringBuffer buffer = new StringBuffer();
buffer.append("---\n"); //this way I detect a "world" at the beginning of the file
while (file.ready()) {
buffer.append(Character.toString((char)file.read()));
}
buffer.append("\n---"); //... and at the end of the file
String[] counter = buffer.toString().split("world");
System.out.println(counter.length-1);
console.close();
file.close();
}
}