Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. package lab6;
  2.  
  3. public class Lab6 {
  4. public static void main(String[] args) {
  5. String word = "Hello";
  6. String text = "H Hello HelloH again Hello Helo lol ok Hello";
  7. int position = 0, counter = 0;
  8. char t = ' ';
  9.  
  10. do {
  11. position = text.indexOf(word, position+1);
  12. char k=((position+word.length())==text.length())?' ':text.charAt(position+word.length());
  13. if (position >= 0 && (t ==k)) {
  14. counter++;
  15. position += word.length();
  16. }
  17. } while (position >= 0);
  18. System.out.println(counter);
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement