Advertisement
Guest User

Ur mom

a guest
Apr 26th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. // A+ Computer Science - www.apluscompsci.com
  2. //Name -
  3. //Date -
  4. //Class -
  5. //Lab -
  6.  
  7. import static java.lang.System.*;
  8.  
  9. public class StringSearch
  10. {
  11. /*
  12. *method countWords will count the occurrences of word in sent
  13. *there may many occurrences of word or none at all
  14. */
  15. public static int countWords(String sent, String word)
  16. {
  17. int count1 = 0;
  18. for(int i = 0; i < sent.length() - 2; i++)
  19. {
  20. if(sent.substring(i, i+2).equals(word))
  21. {
  22. count1++;
  23. }
  24. }
  25. return count1;
  26. }
  27.  
  28. /*
  29. *method countLetters will count the occurrences of letter in sent
  30. *there may many occurrences of letter or none at all
  31. */
  32. public static int countLetters(String sent, String letter)
  33. {
  34. int count = 0;
  35. for(int i = 0; i < sent.length(); i++)
  36. {
  37. if(sent.substring(i, i+1).equals(letter))
  38. {
  39. count++;
  40. }
  41. }
  42. return count;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement