Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

DNA exercise

import java.util.Scanner;

public class DNA {
    public static void main(String[] args) {
        String sequence = StdIn.readString();
        String complementary = "";

        for (int i = 0; i < sequence.length(); i++) {
            char nucleotide = sequence.charAt(i);

            if (nucleotide=='A'){
                complementary += 'T';
            }else if (nucleotide=='T') {
                complementary += 'A';
            }else if (nucleotide=='C'){
                complementary += 'G';
            }else if (nucleotide=='G'){
                complementary += 'C';
            }
        }
        System.out.println(complementary);
    }
}
 
PREVIOUS NEXT
Tagged: #DNA #exercise
ADD COMMENT
Topic
Name
4+4 =