如何将输出(数组的DNA互补物)放入另一个数组以显示输出。

huangapple go评论74阅读模式
英文:

How do I put the output(dna complement of an array into another array to display the output

问题

我正在尝试弄清楚如何将补充方法的输出放入一个数组中,以便我可以显示结果。以下是我的一些代码:

public class BasicBioinformatics {

    public static char[] complement(char[] dna) {
        char[] result = new char[dna.length];
        for (int i = 0; i < dna.length; i++) {
            if (dna[i] == 'A') {
                result[i] = 'T';
            } else if (dna[i] == 'T') {
                result[i] = 'A';
            } else if (dna[i] == 'G') {
                result[i] = 'C';
            } else if (dna[i] == 'C') {
                result[i] = 'G';
            } else {
                return null;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        String testData1 = "GCCTGTCGTAGCTTATC", testData2 = "GGCTGACGTAGCGTAAC";
        char[] result1 = complement(testData1.toCharArray());
        char[] result2 = complement(testData2.toCharArray());
        
        System.out.printf("%s <-- complement --> %s%n", testData1, new String(result1));
        System.out.printf("%s <-- complement --> %s%n", testData2, new String(result2));
    }
}
英文:

I'm trying to figure out how to put the output from a complement method into an array so I can display the results. Here's some of my code:

public class BasicBioinformatics {


public static char[] complement(char dna) {
	for(char d: dna())
		if(d == &#39;A&#39;) {
			d = &#39;T&#39;;
		}
		else if(d == &#39;T&#39;) {
		d = &#39;A&#39;;
	}
		else if(d == &#39;G&#39;) {
		d = &#39;C&#39;;
	}
		else if(d == &#39;C&#39;) {
		d = &#39;G&#39;;
	
		}
		else {
			return null; }
	}
	 
public static void main(String[] args) {
	String testData1 = &quot;GCCTGTCGTAGCTTATC&quot;, testData2 = &quot;GGCTGACGTAGCGTAAC&quot;;
	System.out.printf(&quot;%s &lt;-- complement --&gt; %s%n&quot;, testData1, complement(testData1));
	
}

}

答案1

得分: 1

你有一个名为 function complement(char dna) 的函数,但你试图输入一个 String。你可以改为使用以下代码:

System.out.printf("%s <-- 补码 --> %s%n", testData1, (complement(testData1.toCharArray())));
英文:

You have function complement(char dna) but you try to input a String. You can instead use
System.out.printf(&quot;%s &lt;-- complement --&gt; %s%n&quot;, testData1, (complement(testData1.toCharArray())));

huangapple
  • 本文由 发表于 2020年10月23日 04:50:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/64490367.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定