A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
15
Task/Letter-frequency/Java/letter-frequency-2.java
Normal file
15
Task/Letter-frequency/Java/letter-frequency-2.java
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
public static int[] countLetters(String filename) throws IOException{
|
||||
int[] freqs = new int[26];
|
||||
try(BufferedReader in = new BufferedReader(new FileReader(filename))){
|
||||
String line;
|
||||
while((line = in.readLine()) != null){
|
||||
line = line.toUpperCase();
|
||||
for(char ch:line.toCharArray()){
|
||||
if(Character.isLetter(ch)){
|
||||
freqs[ch - 'A']++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return freqs;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue