Hi I am trying to do some practice in java, I found some difficulties on it. My code:
import java.util.regex.; import java.util.;
public class MyPracticeString {
public static void main(String[] args) {
String dnaSequence;
Scanner in=new Scanner(System.in);
System.out.println("Please input a Sequence of DNA: ");
String dnaInput=in.nextLine();
if (dnaInput.matches("[ATCG]+$")) {
dnaSequence=dnaInput;
int [] count=new int[4];
if (dnaSequence!=null) {
for (int i=0; i<dnaSequence.length(); i++) {
switch(dnaSequence.charAt(i)) {
case 'A':
count[0]++;
break;
case 'T':
count[1]++;
break;
case 'C':
count[2]++;
break;
case 'G':
count[3]++;
break;
default:
System.out.println("Sorry You have invalid Type DNA sequence");
}
}
System.out.println("Now : A"+count[0]);
System.out.println("Now : T"+count[1]);
System.out.println("Now : C"+count[2]);
System.out.println("Now : G"+count[3]);
/*
Pattern p=Pattern.compile("A");
Matcher m=p.matcher(dnaSequence);
int j=0;
while(m.find())
j++;
System.out.println(j);
*/
}
} else {
System.out.println("THE SEQUENCE SHOULD BE CONTAIN ATCG");
}
}
}
Let's say my input AAATATTTTGGGCC , Now how i can compressed this to A3TAT4G3C2 , what is the process i should follow And also how Ii can decompress it again. like how i can get this AAATATTTTGGGCC again
dnaSequencewill never be null.