import java.util.Arrays;
public class StringCount2 {
/**
* 两个字符串中最大相同的子串。 "qwerabcdtyuiop" "xcabcdvbn"
*
*/
public static void main(String[] args) {
String str1 = "qwerabcdtyuiop";
String str2 = "xcabcdvbn";
int count = 0;
String[] s = new String[100];
//循环拆分较短的字符串成为多个子串存放在数组中
for (int i = 0; i < str2.length(); i++) {
for (int j = 1; j < str2.length() - (i - 1); j++) {
if (str1.contains(str2.substring(i, i + j)) == true) {
s[count] = str2.substring(i, i + j);
count++;
}
}
}
//计算数组中不为空的元素个数作为下一个数组的长度
int count2 = 0;
for (int i = 0; i < s.length; i++) {
if (s[i] != null) {
count2++;
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载