Reference no: EM13521
Complete the recursive method match(String x, String y) in the code below which will determine whether or not two strings match. The matching process should allow "wild cards". A '@' character will match with any other single character and a '*' character will match with 0 or more characters of any type.
public class CompareStrings {
public static boolean match(String x, String y) {
... ;
}
public static void main(String args[]) {
System.out.println(match("hello", "hello.")); // should return false
System.out.println(match("hello", "jello")); // should return false
System.out.println(match("hello", "h@llo")); // should return true
System.out.println(match("hello", "h@@@@")); // should return true
System.out.println(match("hello", "h*")); // should return true
System.out.println(match("hello", "*l*")); // should return true
System.out.println(match("anyString", "*")); // should return true
System.out.println(match("help", "h@@@@")); // should return false
System.out.println(match("help", "h*")); // should return true
System.out.println(match("help", "*l*")); // should return true
System.out.println(match("help", "*l*p")); // should return true
System.out.println(match("help", "h@llo")); // should return false
System.out.println(match("", "*")); // should return true
System.out.println(match("", "***")); // should return true
System.out.println(match("", "@")); // should return false
}
}
As a hint, try to first get your code working without wild cards. Then get it working with the '@' character and lastly with the '*' character. Remember to break the Strings apart one letter at a time and that the recursive call should take one or two smaller strings as parameters.