一个字符串str1=“abcd”,另一个字符串str2=“cd”.
str1中包含str1返回true,否则返回false。
public static void main(String[] args) {
String a = "abcd";
String b = "cd";
Boolean boo=getresult(a,b);
System.out.println(boo);
}
public static Boolean getresult(String a, String b) {
Boolean boo=false;
String[] strs = new String[a.length() - 1];
for (int i = 0; i < a.length() - 1; i++) {
strs[i] = a.substring(i, i + 2);
}
for(int j=0;j<strs.length;j++){
System.out.println(strs[j]);
System.out.println(b);
if(strs[j].equals(b)){
boo = true;
break;
}else{
boo = false;
}
}
return boo;
}
|
|