Hi all, I'm trying to teach myself
Java via books, and everything's going fairly smoothly. I'm currently reading through Sams Teach Yourself Java in 24 Hours. I've tried three different books thus far, and I'm liking this one the most.
However, of course, I'm not understanding exactly how this bit of code works, so that's why I'm here! The chapter I'm on is storing information in Arrays, and the book has us making a program that counts the number of specific letters in quotes. E.g. There are 10 uses of the letter 'A', 20 of the letter 'B', and so on.
Here's the source:
http://workbench.cadenhead.org/book/java-6-24-hours/source/chapter9/Wheel.java
So I do clearly understand the
String Phrase part, but I'm having trouble grasping exactly how it's counting the number of letters. This is the code I'm having trouble with:
So I get parts of the code. It's best that I go through the lines that I do understand:
int[] letterCount = new int[26];
I know this is the number of letters in the alphabet.
for (int count = 0; count < phrase.length; count++) {
I know this is making the loop go the total number of arrays in phrase
String current = phrase[count];
char[] letters = current.toCharArray();
I'm just not understanding exactly how the lines from here on out work
I'm thinking I just need someone to plainly spell it out for me. I've tried writing down the steps on paper, but it's not making sense. Any help is greatly appreciated
I think the main thing I'm having trouble comprehending is phrase[count] and I thought I understood .toCharArray, but apparently I'm not.