Last active
December 27, 2015 11:29
-
-
Save EranSch/7319361 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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