Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please help me with this code.

 
deepak bhai
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Find the number of occurrences of given word in a sentence.

why its not working
 
Junilu Lacar
Bartender
Posts: 7481
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this: ItDoesntWorkIsUseless (←click)
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a sentence on paper, and use a pencil to go through the sentence and count not only how many times the word appears in the sentence, but also the index at which you are inspecting the sentence.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you checking the same condition in the while statement and the if inside the while?
 
deepak kushwaha
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for all the help, The code is fixed. Thank you once again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic