MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / isPangram

Method isPangram

src/main/java/com/thealgorithms/strings/Pangram.java:46–60  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 2

testPangramMethod · 0.95
mainMethod · 0.95

Calls

no outgoing calls

Tested by 1

testPangramMethod · 0.76