Thursday 15 May 2014

How i can replace string in java for rewrite the sequence -



How i can replace string in java for rewrite the sequence -

hi trying practice in java, found difficulties on it. 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 sequence of dna: "); string dnainput=in.nextline(); if (dnainput.matches("[atcg]+$")) { dnasequence=dnainput; int [] count=new int[4]; if (dnasequence!=null) { (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 have invalid type deoxyribonucleic acid 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 contain atcg"); } } }

let's input aaatattttgggcc , how can compressed a3tat4g3c2 , process should follow , how ii can decompress again. how can aaatattttgggcc 1 time again

you implement decompress own.

import java.util.scanner; public class compressdecompress { public static void main(string[] args) { scanner in=new scanner(system.in); system.out.println("please input sequence of dna: "); string dnainput=in.nextline(); system.out.println("enter e encrypt or come in d decrypt"); string function=in.nextline(); if("e".equalsignorecase(function)){ system.out.println(compress(dnainput) ); }else if("d".equalsignorecase(function)){ system.out.println(decompress(dnainput) ); }else{ system.out.println("invalid input"); } } private static string compress(string tocompress){ stringbuilder compressedsb = new stringbuilder(); char tempchar=' '; (int i=0,counter=1;i<tocompress.length();i++){ if(tempchar!=tocompress.charat(i)){ tempchar=tocompress.charat(i); compressedsb.append(tempchar); if(counter>1){ compressedsb.append(counter); counter=1; } }else{ counter++; } if (i==tocompress.length()-1){ compressedsb.append(counter); } } homecoming compressedsb.tostring(); } private static string decompress(string todecompress){ homecoming null; } }

and of course of study add together validation using regex or case 'atcg'

java string

No comments:

Post a Comment