This is part of a program that will count the occurrences of each letter within the text file. I want it to print something like A:4 B:23 C:32 and instead it prints A:0B:0C:0A:0B:0C:0A:0B:0C:0 which does not even find all of the occurrences of each letter. What am I doing wrong here? Thanks for the help!!
char ch = line.charAt(0);
int Acounter=0;
int Bcounter=0;
int Ccounter=0;
switch (ch)
{
case 'A':
Acounter++;
break;
case 'B':
Bcounter++;
break;
case 'C':
Ccounter++;
break;
}
bw.write ("A:" + Acounter);
bw.write ("B:" + Bcounter);
bw.write ("C:" + Ccounter);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…