Skip to content

Commit acf7a86

Browse files
TaranjeetSinghKalsiDebasish Biswas
and
Debasish Biswas
authored
Added function in Pangram.java (TheAlgorithms#3703)
* Added function in Pangram.java Added isPangramIndexOf() function in Pangram.java * Added Tests for new function Added Tests for isPangramIndexOf() function * fixed typo * changed function name * changed function name Co-authored-by: Debasish Biswas <debasishbsws.abc@gmail.com>
1 parent b2393d6 commit acf7a86

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/main/java/com/thealgorithms/strings/Pangram.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,23 @@ public static boolean isPangram(String s) {
3636
}
3737
return true;
3838
}
39+
40+
/**
41+
* Checks if a String is Pangram or not by checking if each alhpabet is present or not
42+
*
43+
* @param s The String to check
44+
* @return {@code true} if s is a Pangram, otherwise {@code false}
45+
*/
46+
public static boolean isPangram2(String s) {
47+
if (s.length() < 26) {
48+
return false;
49+
}
50+
s = s.toLowerCase(); // Converting s to Lower-Case
51+
for (char i = 'a'; i <= 'z'; i++) {
52+
if (s.indexOf(i) == -1) {
53+
return false; // if any alphabet is not present, return false
54+
}
55+
}
56+
return true;
57+
}
3958
}
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package com.thealgorithms.strings;
22

3-
import static com.thealgorithms.strings.Pangram.isPangram;
43
import static org.junit.jupiter.api.Assertions.*;
5-
64
import org.junit.jupiter.api.Test;
75

86
public class PangramTest {
97

108
@Test
119
public void testPangram() {
12-
assertTrue(isPangram("The quick brown fox jumps over the lazy dog"));
13-
assertFalse(isPangram("The quick brown fox jumps over the azy dog")); // L is missing
14-
assertFalse(isPangram("+-1234 This string is not alphabetical"));
15-
assertFalse(isPangram("\u0000/\\ Invalid characters are alright too"));
10+
assertTrue(Pangram.isPangram("The quick brown fox jumps over the lazy dog"));
11+
assertFalse(Pangram.isPangram("The quick brown fox jumps over the azy dog")); // L is missing
12+
assertFalse(Pangram.isPangram("+-1234 This string is not alphabetical"));
13+
assertFalse(Pangram.isPangram("\u0000/\\ Invalid characters are alright too"));
14+
15+
assertTrue(Pangram.isPangram2("The quick brown fox jumps over the lazy dog"));
16+
assertFalse(Pangram.isPangram2("The quick brown fox jumps over the azy dog")); // L is missing
17+
assertFalse(Pangram.isPangram2("+-1234 This string is not alphabetical"));
18+
assertFalse(Pangram.isPangram2("\u0000/\\ Invalid characters are alright too"));
1619
}
1720
}

0 commit comments

Comments
 (0)