so I have an assignment about array. It is asked to use Scanner to read through text files and record the occurrences of each alphabet and store them in a table.
For example:
public class something {
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
public void displayTable () {
for (int i = 0; i < alphabet.length; i++) {
System.out.println(alphabet[i] + ": " + count);
}
}
I don't know how to construct the method to store the occurrences of each alphabet.
It is supposed to be like:
public void countOccurrences (Scanner file) {
//code to be written here
}
If the text file only has a line and the line is :
Hello World
The method would ignore any integers or symbols and only output char that appeared in the table.
d: 1
e: 1
h: 1
l: 3
o: 2
r: 1
w: 1
I can't figure this out myself and any help is greatly appreciated!
Thanks, Shy