Checks if a String is considered a Pangram @param s The String to check @return true if s is a Pangram, otherwise false
(String s)
| 44 | * @return {@code true} if s is a Pangram, otherwise {@code false} |
| 45 | */ |
| 46 | public static boolean isPangram(String s) { |
| 47 | boolean[] lettersExisting = new boolean[26]; |
| 48 | for (char c : s.toCharArray()) { |
| 49 | int letterIndex = c - (Character.isUpperCase(c) ? 'A' : 'a'); |
| 50 | if (letterIndex >= 0 && letterIndex < lettersExisting.length) { |
| 51 | lettersExisting[letterIndex] = true; |
| 52 | } |
| 53 | } |
| 54 | for (boolean letterFlag : lettersExisting) { |
| 55 | if (!letterFlag) { |
| 56 | return false; |
| 57 | } |
| 58 | } |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Checks if a String is Pangram or not by checking if each alphabet is present or not |
no outgoing calls