i trying read file called ecoli.txt, contains dna sequence ecoli, , store contents string. tried print string test code. however, when run program, there no output. still new java sure there error in code, need finding it.
package codons; import java.io.*; public class codons { public static void main(string[] args) { try { filereader codons = new filereader("codons.txt"); filereader filereader = new filereader("ecoli.txt"); bufferedreader ecoli = new bufferedreader(filereader); stringbuilder dna_string = new stringbuilder(); string line = ecoli.readline(); while(line != null); { dna_string.append(line); line = ecoli.readline(); } string string = new string(dna_string); system.out.println(string); ecoli.close(); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } } }
edit:
i still having trouble getting program work way wanted attempted complete writing rest of wanted in program , still not getting output. anyway, @ now:
package codons; import java.io.*; import java.util.*; import java.lang.*; import java.text.*; public class codons { public static void main(string[] args) { try { filereader filecodons = new filereader("codons.txt"); filereader filereader = new filereader("ecoli.txt"); bufferedreader ecoli = new bufferedreader(filereader); stringbuilder dna_sb = new stringbuilder(); string line = ecoli.readline(); while(line != null) { dna_sb.append(line); line = ecoli.readline(); } string dna_string = new string(dna_sb); ecoli.close(); bufferedreader codons = new bufferedreader(filecodons); stringbuilder codon_sb = new stringbuilder(); string codon = codons.readline(); while(codon != null) { codon_sb.append(codon); line = codons.readline(); } string codon_string = new string(codon_sb); codons.close(); for(int x = 0; x <= codon_sb.length(); x++) { int count = 0; string codon_ss = new string(codon_string.substring(x, x+3)); for(int = 0; <= dna_sb.length(); i++) { string dna_ss = new string(dna_string.substring(i, i+3)); int result = codon_ss.compareto(dna_ss); if(result == 0) { count += 1; } } system.out.print("the codon '"); system.out.print(codon_ss); system.out.print("'is in dna sequence"); system.out.print(count); system.out.println("times."); } } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } } }
remove ;
after while(line != null)
, causes infinite loop instead of executing next instructions.
the reason explained here: effect of semicolon after 'for' loop (the question c
language, equivalent in java
).
Comments
Post a Comment