public class DNA { public static void main(String[] args) { // -. .-. .-. .-. . // \ \ / \ \ / // / \ \ / \ \ // ~ `-~ `-` `-~ `- String dna1 = "ATGCGATACGCTTGA"; String dna2 = "ATGCGATACGTGA"; String dna3 = "ATTAATATGTACTGA"; String dna = dna3; //System.out.println(dna.length()); int start = dna.indexOf("ATG"); int end = dna.indexOf("TGA"); if (start != -1 && end != -1 && (end - start) % 3 == 0){ System.out.println("Condition 1, 2 and 3 are satisfied."); String protein = dna.substring(start, end+3); //+3 is because int end cuts off at where TGA begins System.out.println("Protein: " + protein); }else{ System.out.println("No protein."); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter