Skip to content
Advertisement

how to count the number of words in each line in Java?

My task is to count the number of words on each line of a text file, separated by space. The text file has 5 lines. I am very new to Java. I have so far this code with the B1TextLoader class and several methods.

JavaScript

My output is:

JavaScript

however, I want it to print something like

JavaScript

How can I achieve this?

my text file, 2-3-1BasicTextFile.txt, looks like this:

JavaScript

Advertisement

Answer

Try This

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement