forked from sayrgyiwoody/java_ex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_17.java
33 lines (26 loc) · 1.03 KB
/
ex_17.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package chapter_9;
import java.util.Scanner;
public class ex_17 {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
System.out.println("Enter a letter or blank to exit: ");
String dna = scn.nextLine();
while(dna.length() != 0) {
//reverse the string with StringBuffer
StringBuffer bf = new StringBuffer(dna);
StringBuffer revBf = bf.reverse();
// replacing T with A , A with T and G with C , C with G
String revCompDna = revBf.toString().replace('A', '#')
.replace('T', 'A')
.replace('#','T')
.replace('G', '#')
.replace('C', 'G')
.replace('#', 'C');
System.out.println("Original DNA :" + dna);
System.out.println("Reverse DNA : " + revBf);
System.out.println("Complement of Reverse DNA :" + revCompDna);
System.out.println("Enter a letter or blank to exit: ");
dna = scn.nextLine();
}
}
}