i know this could be very simple for you guys but i do have a problem with this.
The program searches for a particular array from a text file(i don't know how to import a text file too) and counts the number of occurrence in it. The text file is about DNA sequence. The error in the program says that it has illegal start of expression and i don't know what to replace it or merely i don't actually know what the problem is..hope you guys can help me..thanks a lot.. from a newbie.
import java.io.*;
import java.util.Scanner;
public class GenetiCode
{
//main method
public static void main(String[]code) throws IOException
{
FileReader file = new FileReader("D:\\dna.txt");
BufferedReader fileInput = new BufferedReader(file);
try
{
PrintStream outStream = new PrintStream(new FileOutputStream("D:\\dna.txt"));
outStream.close();
}
catch (IOException e)
{
System.out.println("Error: File could not be opened.");
}
Scanner scan = new Scanner(System.in);
String dna=null;
String dnas[]=new String[5];
//asks for the input
System.out.println("What combination would you like to look for? ");
String combi = scan.nextLine();
String[] array=new String[combi.length()];
scan.close();
array=toArray(combi);
//loop starts here
for(int i=0; i<dnas.length; i++)
{
if (dnas[i]==array[0])
{
for (int j=0; j<array.length &&(i+j)< dnas.length && dnas[i+j]==array[j]; j++)
{
if(j==array.length-1)
{
int occur=0;
occur+=1;
System.out.println(occur + " position is at " + i);
}
}
}
System.out.println("The number of occurence is: " + occur);
printArray(dnas);
printArray(array);
}
//converts it to array
private static String[] toArray(String dna)
{
String seq[]=new String[dna.length()];
int x=0;
for(int i=0; i<dna.length(); i++)
{
char z=dna.charAt(i);
if(true)
{
System.out.println("Char z=" + z);
seq[x++]=String.valueOf(z);
}
}
return seq;
}
//prints the array
public static void printArray(String dnas[])
{
for(int i=0; i<dnas.length; i++)
{
System.out.println("DNA[" + i + "]=" + dnas[i]);
}
}
}