Looking for help with a basic array problem. Program has to read a sentence and store the frequencies of the word lengths in an array and then print out how many words are 1 letter words, 2 letter words etc.
I'm a pretty raw java programmer but have made a stab at it below would greatly appreciate some guidance. What I have seems to compile but spits out some garbled hex when I run the program and enter a sentence.
When I enter a sentence into the program I get an output like this:
[I@eb42cbf
[I@eb42cbf
[I@eb42cbf
[I@eb42cbf
[I@eb42cbf
[I@eb42cbf
My code:
class WordCount
{
public static void main(String[] args)
{
int wordList[] = new int[20];
System.out.println("Please enter a sentence.");
for (int i = 0; i <= wordList.length; i++)
{
String s = Console.readToken();
int x = s.length();
wordList[x]++;
}
int x = 1;
while (x < wordList.length)
{
if (wordList[x] > 0)
System.out.println(x + "-letter words: " + wordList[x]);
x++;
}
}
}
countcome from? You did not define it. Maybe that should bewordList.iin the second loop starts from1. I think it should start from0.