本文目录
1、计算字符串中指定字符最大连续出现的次数(代码片段)
2、java如何计算字符串中字符出现的最大次数
//连中次数
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;
java如何计算字符串中字符出现的最大次数