简体   繁体   English

返回给定字符串中重复次数最多的字符

[英]Return the most repeated character from a given string

I need help finding the error. 我需要寻找错误的帮助。 The practice problem asks to return the most common character from a given string. 练习问题要求返回给定字符串中最常见的字符。

The error I receive is: String index out of range: 4 我收到的错误是:字符串索引超出范围:4

    for (int i=0; i<input.length(); i++){
        // code
        for (int j=0; j<input.length(); i++){
            //code
            }
        }       

In your second for loop you are incrementing the variable i instead of j . 在第二个for循环中,您将递增变量i而不是j You should do this : 你应该做这个 :

for(int j = 0; j < input.length(); j++)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM