File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed
main/java/com/thealgorithms/strings
test/java/com/thealgorithms/strings Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -36,4 +36,23 @@ public static boolean isPangram(String s) {
36
36
}
37
37
return true ;
38
38
}
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
+ }
39
58
}
Original file line number Diff line number Diff line change 1
1
package com .thealgorithms .strings ;
2
2
3
- import static com .thealgorithms .strings .Pangram .isPangram ;
4
3
import static org .junit .jupiter .api .Assertions .*;
5
-
6
4
import org .junit .jupiter .api .Test ;
7
5
8
6
public class PangramTest {
9
7
10
8
@ Test
11
9
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" ));
16
19
}
17
20
}
You can’t perform that action at this time.
0 commit comments