The result that you get***aaaaaaaaaaaaaaaaaaa
and this loop
index = 0;
for(int d = 1; d < 27; d++){
if(occurrences[d] > occurrences[index])
index = d;
}
indicates that that the every item in the occurrences array is 0. This means that your algorithm defaults to appending array[0]
to the text_generated
string. This means that the problem is in this block
for(int c = 0; c <= text_formatted.length() -n-1;c++){
if(text_formatted.substring(c,c+n+1).equals(curr_word.append(array[b])))
count += 1;
}
Possible problems:
- The loop is never entered,
text_formatted.length() - n - 1
results in a negative value. - The
if
always evaluates tofalse
.
In both cases the problem is most likely related to the values of n
and text_formatted
.