My code is returning all the letters with a counter of zero. I am not sure why this problem is occurring.
public class LetterFrequencies {
public static void main(String[] args) {
String letters = "abcdefghijklmnopqrstuvwxyz";
String phrase = "This is a phrase!";
System.out.println("The following shows the letter frequencies for the phrase");
/* your code here */
int counter = 0;
for (int i = 0; i <= 25; i++) {
for (int j = 0; j <= 16; j++) {
if (letters.substring(i, i + 1) == phrase.substring(j, j + 1)) {
counter++;
}
}
System.out.println(letters.substring(i, i + 1) + counter);
}
}
}
Aucun commentaire:
Enregistrer un commentaire