【发布时间】:2016-01-14 16:15:45
【问题描述】:
我正在尝试计算并返回两个长度相等的 DNA 序列不同的地方。例如,给定字符串“ATGT”和“GTGA”,结果应该是数组 { true, false, false, true }。我收到一个 False/true 错误,无法解析为一个变量,这是我到目前为止得到的结果
/**
* Calculates and returns where two DNA sequences of equal lengths differ. For
* example, given strings "ATGT" and "GTGA", the result should be array
* { true, false, false, true }.
*
* @param dna1 a String representing a DNA sequence of arbitrary length (equal
* to dna2's length), containing only the characters A, C, G and T
* @param dna2 a String representing a DNA sequence of arbitrary length (equal
* to dna1's length), containing only the characters A, C, G and T
* @return an array of boolean values, of length equivalent to both
* parameters' lengths, containing true in each subscript where the
* parameter strings differ, and false where they do not differ
*/
public static boolean[] mutationPoints(String dna1, String dna2) {
boolean [] mutPoint = new boolean [dna1.length()];
for( int i = 0; i < i; i++) {
if( dna1 != dna2) {
mutPoint[i] = False;
}
else if (dna1 == dna2) {
mutPoint[i] = True;
}
}
【问题讨论】:
-
使用小写
true&false。 -
你想用
for( int i = 0; i < i; i++) {达到什么目的@这总是0 -
true和false都小写,但下一个谜团将是循环条件`i -
使用 equals 比较两个字符串,你的循环也神秘地构建了。我们从不进入。