COMP2243 - Programming and Problem Solving

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Text Processing DNA.java EggyPeggy.java



DNA Program


Description

The genetic information in DNA is encoded as a sequence of four chemical bases:

Adenine(A)

Guanine(G)

Cytosine(C)

Thymine(T)

This program inputs a DNA sequence and calculates the GC content.

Associated Concepts:

String

Algorithm:

main method:

Input a DNA sequence from the keyboard

Call gcContent method and pass the argument to get the result

Print the result

Method gcContent definition

Declare variable gcCount and initialize it to 0

Loop: go through each letter in the DNA sequence

     Retrieve the letter at index i

     If the letter is G or C

         Increment the count

Calculate and return the GC-content

Source Code



Sample Run



Video