Java - Solution works but fails to pass first task


I completed the challenge for Building a Word Counter in Java. The solution works perfect but, it fails on the first task that output the filename. (Below the sandbox url).

*** The task that fails is the filename input with Scanner and output it to the terminal.

Sandbox URL

Hey Rosibel,

Thanks for reaching out! The reason the first task does not pass when you copy in the solution is that it is asking for only the filename to be output. The solution has the code for both the filename and the word to be output. In order for the first task to pass, you will have to do each section one at a time.

The following is the solution that will pass:
public class WordCount {
	public static void main(String[] args) {
        // Declare variables
        String filename = "", word = "";
        Scanner scanner = new Scanner(;

        // Get user input for filename and word
        System.out.println("Enter the filename to search.");
        filename = scanner.nextLine();
1 Like

Thanks lorraine, I followed your suggestion and works perfect. I appreciate it.

1 Like