Hi, finishing my first year of C.S., and now I'm stuck on my last homework problem. I need to check whether a user entered String is a Blurb. A Blurb is a Whoozit followed by one or more Whatzits. A Whoozit is the character ‘ x’ followed by zero or more ‘ y’s. A Whatzit is a ‘ q’ followed by either a ‘ z’ or a ‘ d’, followed by a Whoozit. It keeps returning false, even though it's true. I used the debugger to find out that it is returning false when it's checking whether the first whatzit is a "qd" or "qf." I'm typing in xqdx, and for some reason it's telling me that it isn't qd, I guess. The problem is in the isWhatzit() method.
import java.util.*; public class CheckBlurb { static int count = 0; public static void main(String[] args) { String userInput; Scanner scan = new Scanner(System.in); System.out.println("Enter a blurb."); userInput = scan.next(); boolean isValid; int checkStart = isWhoozit(userInput); if(checkStart == 0) { isValid = false; } else { String nextCheck = (userInput.substring(checkStart)); isValid = isWhatzit(nextCheck); } if(isValid == true) { System.out.println("Yep, that is a Blurb."); } else { System.out.println("Nope, not a Blurb, sorry."); } } public static int isWhoozit(String str) { if(str.charAt(count) == 'x') { count ++; while(str.charAt(count) == 'y') { count++; } } else { count = 0; } return count; } public static boolean isWhatzit(String str) { if(str.substring(0,1) != "qd" || str.substring(0,1) != "qz") { return false; } str = str.substring(2); int nextWhoozit = isWhoozit(str); if (nextWhoozit == 0) { return false; } else if (nextWhoozit >= str.length()) { return true; } else { return isWhatzit(str.substring(nextWhoozit)); } } }