I have this program and I need it to count the lower and uppercase A's in a data file. I'm not sure what to use between charAt or substring. It's also all in a while loop, and I was getting at the fact that maybe I need to use the next() method? Maybe? I just need to find these characters and count them up in total.
import static java.lang.System.*;
import java.util.*;
import java.io.*;
public class Java2305{
public static void main(String args[]){
new Solution();
}}
class Solution
{
private Scanner fileScan;
Solution()
{
run();
}
void run()
{
int count = 0;
try
{
fileScan = new Scanner(new File("letters01.dat"));
while(fileScan.hasNext() )
{
String getA = fileScan.substring("A");
out.println(getA);
count++;
}
}
catch(Exception e){}
out.println();
out.println("The letter 'A' occurs "+count+" times.");
out.println();
out.println();
}
}