Skip to content

Instantly share code, notes, and snippets.

@matty234
Created May 2, 2017 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matty234/90cfdeaf2994bc4c52b8d8e6828f4655 to your computer and use it in GitHub Desktop.
Save matty234/90cfdeaf2994bc4c52b8d8e6828f4655 to your computer and use it in GitHub Desktop.
import java.util.*;
import java.io.*;
public class BestAlphabetty {
public static void main(String... args) throws FileNotFoundException {
Scanner sc = new Scanner(new File("words.txt"));
int[] a = new int[26];
int lc = 0;
for (String line=(sc.hasNextLine())?sc.nextLine():"";
sc.hasNextLine(); line=sc.nextLine(), lc=((lc==0)?2:lc+1))
a[Character.toLowerCase(line.charAt(0)) - 'a'] ++;
for (char i = 'a'; i <= 'z'; i++)
System.out.printf("%c: %d\n", i, a[i - 'a']);
System.out.printf("Line Count: %d\n", lc);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment