Java 有方法错误的最常见字母
试图对数组进行计数,但无法将其与任何其他类型的变量一样处理 每次我尝试与其他一些方法一起编译时,都会出现一个缺少方法体的错误 错误,不确定我遗漏了什么Java 有方法错误的最常见字母,java,loops,counter,Java,Loops,Counter,试图对数组进行计数,但无法将其与任何其他类型的变量一样处理 每次我尝试与其他一些方法一起编译时,都会出现一个缺少方法体的错误 错误,不确定我遗漏了什么 public static char maxLetterRecurrence(String sampleInput, int[]count); { int length=sampleInput.length(); int letterCount = 1; int max = 0; char max
public static char maxLetterRecurrence(String sampleInput, int[]count);
{
int length=sampleInput.length();
int letterCount = 1;
int max = 0;
char maxChar = 0;
for(int i=1; i<length; i++)
{
if(count[i]==count[i-1])
{
letterCount++;
}
else
{
if(letterCount>max)
{
max=letterCount;
maxChar=count[i-1];
}
}
return maxChar;
}
}
publicstaticcharmaxletterecurrency(字符串sampleInput,int[]count);
{
int length=sampleInput.length();
int-letterCount=1;
int max=0;
char maxChar=0;
对于(int i=1;imax)
{
最大值=信数;
maxChar=计数[i-1];
}
}
返回maxChar;
}
}
更改此行
public static char maxLetterRecurrence(String sampleInput, int[]count);
到
结尾不应该有分号。谢谢!仍然无法比较我的maxChar=count[i-1];我不知道如何将最大发生次数存储到变量中。您正在尝试将
int
转换为char
,尽管我不理解您尝试使用的逻辑。
public static char maxLetterRecurrence(String sampleInput, int[]count)