I want to count the number of each alphabetic character in this text file, unless the line begins with a ">" in which case it will simply write that line to the file. This is what I have, and it will not compile because it says "error: cannot find symbol
" and points to the period in my for-statement line.length
.
Why isn't this working??
String line;
while ((line = br.readLine () ) != null)
{
if (line.startsWith( ">" ))
{
line += "\t";
bw.write (line);
}
else
{
int aCounter=0;
int bCounter=0;
int cCounter=0;
for (int m=0; m < line.length; m++)
{
char letter = line.charAt(m);
switch (letter)
{
case 'A':
aCounter++;
break;
case 'B':
bCounter++;
break;
case 'C':
cCounter++;
break;
}
}
bw.write( "A:" + aCounter + " B:" + bCounter + " C:" + cCounter);
}
file to be read sample:
this is a program that will count characters abcdabcdababab
wanted program output:
this is a program that will count characters a:5 b:5 c:2 d:2