Issue
strong textI would like to encode binary sequence to DNA sequence by truth table : 00=A 01=C 10=G 11=T For example:11000110=``TACG By using java, and I haven't Does someone can help me PLEASE ?
my code that half I have done String ddna=" ";
Dictionary phoneBook = new Hashtable();//creating dictionary in java we can use hashtable
// put() method
phoneBook.put("00", "A");
phoneBook.put("01", "G");
phoneBook.put("10", "C");
phoneBook.put("11", "T");
Solution
If your table is fixed you can simply use if
statements to determine the correct letter like this:
public static String convert(String input) {
if (input.length() % 2 == 1) {
return "";
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < input.length(); i += 2) {
if (input.charAt(i) == '0') {
if (input.charAt(i + 1) == '0') {
sb.append("A");
} else {
sb.append("G");
}
} else {
if (input.charAt(i + 1) == '0') {
sb.append("C");
} else {
sb.append("T");
}
}
}
return sb.toString();
}
Answered By - JANO
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.