Repository: TheAlgorithms/Java
Pull request #3703 (2022-10-27 13:53:34)

Added function in Pangram.java
<!-- For completed items, change [ ] to [x] -->
  Added new isPangramIndexOf() function in Pangram.java and updated its JUnit Tests in PangramTest.java

- [x] I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/CONTRIBUTING.md).
- [x] This pull request is all my own work -- I have not plagiarized it.
- [x] All filenames are in PascalCase.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.



Patch:
diff --git a/src/main/java/com/thealgorithms/strings/Pangram.java b/src/main/java/com/thealgorithms/strings/Pangram.java
index a87f6f20..71924e0b 100644
--- a/src/main/java/com/thealgorithms/strings/Pangram.java
+++ b/src/main/java/com/thealgorithms/strings/Pangram.java
@@ -36,4 +36,23 @@ public class Pangram {
         }
         return true;
     }
+    
+    /**
+     * Checks if a String is Pangram or not by checking if each alhpabet is present or not
+     *
+     * @param s The String to check
+     * @return {@code true} if s is a Pangram, otherwise {@code false}
+     */
+    public static boolean isPangram2(String s) {
+        if (s.length() < 26) {
+            return false;
+        }
+        s = s.toLowerCase(); // Converting s to Lower-Case
+        for (char i = 'a'; i <= 'z'; i++) {
+            if (s.indexOf(i) == -1) {
+                return false; // if any alphabet is not present, return false
+            }
+        }
+        return true;
+    }
 }


Test patch:
diff --git a/src/test/java/com/thealgorithms/strings/PangramTest.java b/src/test/java/com/thealgorithms/strings/PangramTest.java
index 599ed3d5..d3789d49 100644
--- a/src/test/java/com/thealgorithms/strings/PangramTest.java
+++ b/src/test/java/com/thealgorithms/strings/PangramTest.java
@@ -1,17 +1,20 @@
 package com.thealgorithms.strings;
 
-import static com.thealgorithms.strings.Pangram.isPangram;
 import static org.junit.jupiter.api.Assertions.*;
-
 import org.junit.jupiter.api.Test;
 
 public class PangramTest {
 
     @Test
     public void testPangram() {
-        assertTrue(isPangram("The quick brown fox jumps over the lazy dog"));
-        assertFalse(isPangram("The quick brown fox jumps over the azy dog")); // L is missing
-        assertFalse(isPangram("+-1234 This string is not alphabetical"));
-        assertFalse(isPangram("\u0000/\\ Invalid characters are alright too"));
+        assertTrue(Pangram.isPangram("The quick brown fox jumps over the lazy dog"));
+        assertFalse(Pangram.isPangram("The quick brown fox jumps over the azy dog")); // L is missing
+        assertFalse(Pangram.isPangram("+-1234 This string is not alphabetical"));
+        assertFalse(Pangram.isPangram("\u0000/\\ Invalid characters are alright too"));
+        
+        assertTrue(Pangram.isPangram2("The quick brown fox jumps over the lazy dog"));
+        assertFalse(Pangram.isPangram2("The quick brown fox jumps over the azy dog")); // L is missing
+        assertFalse(Pangram.isPangram2("+-1234 This string is not alphabetical"));
+        assertFalse(Pangram.isPangram2("\u0000/\\ Invalid characters are alright too"));
     }
 }