-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPangramChecker.java
More file actions
40 lines (29 loc) · 993 Bytes
/
Copy pathPangramChecker.java
File metadata and controls
40 lines (29 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.company.Assign4;
// WAP to implement pangram checking with the least inbuilt methods being used
public class PangramChecker {
public static boolean isPangram(String str) {
str = str.replaceAll("\\s", "").toLowerCase();
boolean[] letters = new boolean[26];
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c >= 'a' && c <= 'z') {
letters[c - 'a'] = true;
}
}
for (boolean letter : letters) {
if (!letter) {
return false;
}
}
return true;
}
public static void main(String[] args) {
String sentence = "The quick brown fox jumps over the lazy dog";
boolean isPangram = isPangram(sentence);
if (isPangram) {
System.out.println("The sentence is a pangram.");
} else {
System.out.println("The sentence is not a pangram.");
}
}
}