Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. public int wordCount(String s1)
  2. {
  3. String check = new String();
  4. int counter = 0;
  5. String one = this.str.toLowerCase();
  6. String two = s1.toLowerCase();
  7. for (int i = 0; i <one.length() - (two.length() +1); i++)
  8. {
  9. check = one.substring(i,(i+two.length()));
  10. if(check.equals(two))
  11. {
  12. if ((one.charAt(two.length() +1) == ' ' || one.charAt(two.length() +1) == '.') && (one.charAt(i-1) == ' ' || i == 0))
  13. {
  14. counter++;
  15. }
  16. }
  17. }
  18. return counter;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement