• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Word Counter - just count odd lines?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all
I am new to Java and doing a code to count the specific words in a text file and print them with the line number.
The code below is the sample main method which I havenot combined with other classes.
The problem I encountered is that this main method only print the odd lines in the text files. Anyone can show me how to resolve it? Thanks.
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You first problem lies here:

In the if statement itself, you call inFile.readLine() which reads a line but you don't do anything with it so it gets lost. Whenever you read a line, you need to store/use it. Since this sounds like a homework problem, I won't give you the answer but that should get you on the right track.
Brian
reply
    Bookmark Topic Watch Topic
  • New Topic