【发布时间】:2021-12-29 16:40:03
【问题描述】:
在我的课堂上,我的任务是用 Java 编写一个程序,告诉你存储在一个数组中的 2 个长度为 8 的 DNA 序列是否相同。然而,序列可以是循环的。比如这两个是一样的:
A T G C G T A T
A T A T G C G T
我编写的代码检查索引 0 处的两个数组是否相同,如果它们相同,则转到检查数组方法,如果不是,则将 1 添加到第二个数组的索引并重新开始。但是我很困惑,因为我不确定如何输入检查方法通过两个数组的新索引,或者如何循环索引(即从 7 回到 0)。
对不起,如果代码是垃圾,我是一个初学者,发现这个问题很混乱。 在此先感谢:)
/* checking whether the two arrays are equal at a certain index
for (x=0;x<8;) {
for (y=0;y<8;) {
if (DNAarray1[x] == DNAarray2[y]) {
isEqual(ADNarray1, ADNarray2);
} else y++;
}
}
/* isEqual method - my issue is with how I can take x and y from above and carry them into this method.
And also how to loop this back round so the index of y goes from 7 back to 0.
static boolean isEqual(int[] ADN1, int[] ADN2) {
for (int c = 1; c < 8; c++) {
if (ADN1[x + c] == ADN2[y + c]) {
return true;
} else return false;
}
}
【问题讨论】:
标签: java arrays indexing sequence cyclic