Counting words

  • 20
  • Locked
Read a file name from the console. The file contains words separated by punctuation marks. Output to the console the number of times the word "world" appears in the file. Close the streams.
You can't complete this task, because you're not signed in.
Comments (7)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Олег Байбула
Level 32 , Ukraine
3 March, 13:16
Easy task. Just one Stream API pipeline.
Justin Smith
Level 39 , Greenfield, USA, United States
14 October 2021, 15:09
Two things likely to trip you up on this task that, on the surface, looks extremely simple: 1. returns a character in numeric form. You must cast it correctly to append it to a string. 2. The word "world" must appear by itself, not as part of another word. So you can't just loop through String.indexOf.
Gellert Varga
Level 23 , Szekesfehervar, Hungary
21 September 2021, 12:07
A more precise description of the task is: - "The file contains words separated by punctuation marks and/or whitespaces." - the words "world" count only in lower case. - "worlds", "worldly" : these do not count.
Level 22 , Austin, United States
28 April 2020, 07:38
Hey Crew. So what worked for me on this one was the following. Convert the file to an ArrayList<Character> charArray... containing each char in the file. Convert charArray into ArrayList<String> words using the ASCII value for characters. (97 to 122 for lower case.. Character.toLowerCase() ) Check if each of those words equals "world" using a for loop. Hope this helps!
Level 31 , Podol'sk, Russian Federation
27 May 2019, 12:34
"Determine why the program found more instances of the word "world " than exist in the file." I don't know why? when I check it with file on my PC it works.
Abhishek Rangari
Level 22 , Nagpur, India
25 November 2018, 08:56
Can anyone help me on this, not sure what is going wrong
Level 41
26 November 2018, 07:29
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at