Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab6;
- public class Lab6 {
- public static void main(String[] args) {
- String word = "Hello";
- String text = "H Hello HelloH again Hello Helo lol ok Hello";
- int position = 0, counter = 0;
- char t = ' ';
- do {
- position = text.indexOf(word, position+1);
- char k=((position+word.length())==text.length())?' ':text.charAt(position+word.length());
- if (position >= 0 && (t ==k)) {
- counter++;
- position += word.length();
- }
- } while (position >= 0);
- System.out.println(counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement