[java][homework] Having trouble adding values to a scoreboard type array via /r/learnprogramming


[java][homework] Having trouble adding values to a scoreboard type array

I've been writing a two class program which reads a text file, and then returns the frequency of the words. I've used the split method to add each word to a string array. Then, I'm trying to use the length of the word as the position in a new scoreboard array and adding one to that position. The problem seems to be that after finding the length of each string, my scoreboard array isn't being updated correctly (one position is receiving 25% of the scores). I've copied the relevant section of my code.

double[] percentArray = new double[17]; public void analyzeFile(String line) { line = line.toLowerCase(); String[] wordArray = line.split("[ ,.?!;:]"); lengthCount = new long[17]; for(String k : wordArray) { wordLength = k.length(); if((wordLength > 0) && (wordLength <= 15)) { pos = wordLength - 1; lengthCount[pos]++; } } 

Submitted July 10, 2017 at 03:17PM by generic_panda
via reddit http://ift.tt/2u1pW5t

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s