I have written a code to find the frequency of each letter of the alphabet in a txt file in Java and write the results in another file .The problem is that frekuenca(String text) has an error cause it must return a result of type String.Can you think of a way to solve it? Thank you!
public class Frekuenca_File {
public static void main(String args[]) throws FileNotFoundException {
Scanner input = new Scanner(new File("teksti.txt"));
PrintStream output = new PrintStream(new File("frekuenca.txt"));
while (input.hasNextLine()) {
String fjala = input.next();
output.print(frekuenca(fjala));
}
}
public static String frekuenca(String text) {
int frekuenca = 0;
for (int i = 'a'; i <= 'Z'; i++) {
for (int j = 0; j < text.length() - 1; j++) {
if (i == text.charAt(j)) {
frekuenca++;
}
}
String result = "" + i + ":" + frekuenca;
return result;
}
}
}