java.lang.StringIndexOutOfBOundsException错误我做错了什么 public int counts与rightshift匹配(DNAStrand-other,int-shift){ 对于(j=0;j
这条线是不可靠的java.lang.StringIndexOutOfBOundsException错误我做错了什么 public int counts与rightshift匹配(DNAStrand-other,int-shift){ 对于(j=0;j,java,javascript,eclipse,Java,Javascript,Eclipse,这条线是不可靠的 public int countMatchesWithRightShift(DNAStrand other, int shift){ for (j = 0; j < (data.length()); ++j){ other.data.charAt(j = other.data.charAt(j)+shift); } for (i = 0; i <other.length()-data.length(); ++i){
public int countMatchesWithRightShift(DNAStrand other, int shift){
for (j = 0; j < (data.length()); ++j){
other.data.charAt(j = other.data.charAt(j)+shift);
}
for (i = 0; i <other.length()-data.length(); ++i){
if (other.data.charAt(i) == 'T' && data.charAt(i) == 'A'){
rightShift++;
}
else if (other.data.charAt(i) == 'A' && data.charAt(i) == 'T'){
rightShift++;
}
else if (other.data.charAt(i) == 'C' && data.charAt(i) =='G'){
rightShift++;
}
else if (other.data.charAt(i) == 'G' && data.charAt(i) =='C'){
rightShift++;
}
}
return rightShift;
}
您的意思是通过执行以下操作来设置字符串中字符的值吗
other.data.charAt(j = other.data.charAt(j)+shift);
这也是不可能的,因为字符串是不可变的
试一试
//索引关闭的警告测试(此处没有IDE)错误发生在哪一行?仅从提供的信息很难看出。您可以发布堆栈跟踪和/或代码的其余部分吗?但正如标题所示,我假设其他。数据的长度比您预期的要短。为什么标记为javascript?请您用fi中的偏执词更正错误rst代表循环。有趣的是,它可能会编译并运行。@EnginKayraklioglu看到我的答案了吗
other.data.charAt(j) = other.data.charAt(j)+shift;
String other.data = other.data.substring(0,j) + other.data.charAt(j)+shift
+other.data.substring(j + 1);