My goal is to get the most frequent character referred to in the title by:
- Storing character-set in an array
- Rearranging the array - somehow - as Unicode-numbers
- Comparing the array-elements by having a loop notice the greatest number of times a character occurs (So they can't be outdone by the other-occurrences) to the point of getting the needed one back as a character
- Returning the most-frequent-character to the main-method
Here is the method-code I'm using: (w/some extra variable-declarations, just in case.)
// For telling the most frequent character in a String. public static char mostFrequent(String charToFind) { // Use this array(s) that tracks the highest-frequency-character. char wordArray[] = new char[16]; char frequentFound[] = new char[16]; char charsToCount, freqChar; int iterator, mostFreqNum = 0, frequentOne[] = new int[16], buildUp = 0, freqNum = 0, highestFreq = 0, loopCon = 16, redoer = 1; int startSearch, index, iteration = 0, minValue, minIndex; wordArray = charToFind.toCharArray(); for (int reiterate = 0; reiterate <= 15; reiterate++) { frequentOne[reiterate] = (int) wordArray[reiterate]; } for (startSearch = 0; startSearch <= 15; startSearch++) { minIndex = startSearch; minValue = frequentOne[startSearch]; for (index = startSearch + 1; index < 15; index++) { if (frequentOne[index] < minValue) { minValue = frequentOne[index]; minIndex = index; } } frequentOne[minIndex] = frequentOne[startSearch]; frequentOne[startSearch] = minValue; } while (15 >= 0) { iteration++; while (14 >= 0) { redoer++; if (frequentOne[iteration] < frequentOne[redoer]) { freqNum = frequentOne[redoer] - frequentOne[iteration]; } if (frequentOne[iteration] > frequentOne[redoer]) { freqNum = frequentOne[iteration] - frequentOne[redoer]; } } } freqChar = (char) freqNum; return freqChar; }
Now here is the compiler's current-complaint: It refers to the second-to-last statement as unreachable, so what is trying to reach it, and how can I correct this?