import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class $ {
public static void main(String[] args) {
int tmp;
while (true) {
tmp = (int) (Math.random() * 10000000);
if (tmp >= 1000000 && tmp <= 9999999) {
break;
}
}
System.out.println(tmp);
String str = tmp + "";
List maxList = new ArrayList();
int maxLen = 1;
String oldKey = str.substring(0, 1);
for (int i = 1; i
String newKey = str.substring(i, i + 1);
if (oldKey.equals(newKey)) {
maxLen++;
} else {
maxList.add(maxLen);
oldKey = newKey;
maxLen = 1;
}
}
int max = Collections.max(maxList);
System.out.println(maxList);
System.out.println(max);
}
}
给你个确定最大连续长度的方法吧,得到了最大长度,后面的判断用就好办了