Skip to content

Instantly share code, notes, and snippets.

@EranSch
Last active December 27, 2015 11:29
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 EranSch/7319361 to your computer and use it in GitHub Desktop.
Save EranSch/7319361 to your computer and use it in GitHub Desktop.
public class Pangram{
public static void main( String [] args ){
Pangram p = new Pangram();
p.pangramer("The quick brown fox jumps over the lazy dog.");
p.pangramer("Pack my box with five dozen liquor jugs");
p.pangramer("Saxophones quickly blew over my jazzy hair");
}
void pangramer( String text ){
int [] nums = new int[26];
boolean isPangram = true;
char[] chars = this.splitter(text);
// Tally letters
for( char c : chars ){
nums[(Character.getNumericValue(c) - 10)] += 1;
}
// See if pangram
for( int p : nums ){
if(p==0) isPangram = false;
}
System.out.print(isPangram + " -> ");
// Print stats
for( int i=0; i<26; i++){
System.out.print( ((char)(i+97)) + ": " + nums[i] );
if( i+1 != 26 ) System.out.print(", ");
}
System.out.println("\n");
}
char [] splitter( String line ){
line = line.replaceAll("[^a-zA-Z]", "");
char [] chars = line.toLowerCase().toCharArray();
return chars;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment