计算字符串中指定字符最大连续出现的次数

//连中次数
public
static int LzNum(String str) { // 分割成数组 char[] c = str.toCharArray(); // 定义一个记住最大次数的变量 int max = 0; // 循环比较 for (int i = 0; i < c.length; i++) { // 定义一个中间值 int is = 1;// 以为是两两比较所以中间会上一次,就像断木头一样,你想想哈 for (int j = i; j < c.length - 1; j++) { if (c[j] == c[j + 1] && c[j] == '1') { is++; } else { break; } if (is > max) { max = is; } } } return max; }
原文地址:https://www.cnblogs.com/zhuzhen/p/9475171.html