这是我到目前为止所做的递归,但它似乎不正确,这主要是出于兴趣。任何帮助或提示将不胜感激。
public class CompareStrings {
public static boolean match(String x, String y) {
//turn each string into a char[], sort that array,
//then compare the two Simple
char[] first = x.toCharArray();
char[] second = y.toCharArray();
java.util.Arrays.sort(first);
java.util.Arrays.sort(second);
String sorted_str1 = new String(x);
String sorted_str2 = new String(y);
if(sorted_str1.equals(sorted_str2)){
return true;
}
else{
return false;
}
}
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
}
}