0
我是新來的,所以沒有火焰請。StringIndexOutOfBoundsException解決方案CodingBat maxBlock
我知道我可以在網上找到解決方案,但我做不到,但我無法理解
StringIndexOutOfBoundsException
錯誤是如何發生在我的代碼中的。
public int maxBlock(String str) {
int max = 0;
for(int i = 0; i < str.length() - 1; i++){
int c1 = 0;
for(int j = i + 1; i < str.length(); j++){
if(str.charAt(i) == str.charAt(j) && j - i == 1)
c1++;
}
if(c1 > max)
max = c1;
}
return max;
}
編輯:解決:d
錯字:'int j = i + 1;我'int j = i + 1; j
Tunaki
什麼是錯誤?如果你試圖在這裏遵守規則,沒有人會責罵你,放鬆 –
@Tunaki神聖的地獄,謝天謝地:D –