英文:
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 == 'A') {
d = 'T';
}
else if(d == 'T') {
d = 'A';
}
else if(d == 'G') {
d = 'C';
}
else if(d == 'C') {
d = 'G';
}
else {
return null; }
}
public static void main(String[] args) {
String testData1 = "GCCTGTCGTAGCTTATC", testData2 = "GGCTGACGTAGCGTAAC";
System.out.printf("%s <-- complement --> %s%n", 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("%s <-- complement --> %s%n", testData1, (complement(testData1.toCharArray())));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论