Java判断字符串是否存在某几位连续字符相同


code:

private boolean isUserIdHaveSameNum(String str) {
int num = 5;
char[] chars = str.toCharArray();
int count = 0;
for (int i = 0; i < chars.length - 1; i++) {
if (chars[i] == chars[i + 1]) {
count++;
} else {
count = 0;
}
if (count >= (num - 1)) {
return true;
}
}
return false;
}


输入:12888885

> true

输入:12234568

> false

输入:55555

> true

java
发布

街角有人祝福,巷口有人哭,这里却没人评论ε=(´ο`*)))