Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PlayTime {
- public static void main(String[] args) {
- String string = "isnotis xxnotx isnononot";
- System.out.println(equalsIsNot(string));
- }
- static boolean equalsIsNot(String string) {
- int nIs = countOccurences(string, "is");
- int nNot = countOccurences(string, "not");
- return nIs == nNot;
- }
- //helper method...
- static int countOccurences(String str, String sub) {
- int count = 0, len = sub.length();
- for (int i = 0; i <= (str.length() - len); i++) {
- String it = str.substring(i, i + len);
- if (it.equals(sub)) {
- count++;
- }
- }
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement