-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckPangram.java
More file actions
35 lines (31 loc) · 1.01 KB
/
CheckPangram.java
File metadata and controls
35 lines (31 loc) · 1.01 KB
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
public class CheckPangram {
public static boolean isPangram(String sentence) {
sentence = sentence.toLowerCase();
boolean[] foundLetters = new boolean[26];
int totalLetters = 0;
for (int i = 0; i < sentence.length(); i++) {
char current = sentence.charAt(i);
if (current >= 'a' && current <= 'z') {
int index = current - 'a';
if (!foundLetters[index]) {
foundLetters[index] = true;
totalLetters++;
}
}
}
if (totalLetters == 26) {
return true;
} else {
return false;
}
}
public static void main(String[] args) {
String input = "The quick brown fox jumps over the lazy dog";
boolean result = isPangram(input);
if (result) {
System.out.println("The sentence is a Pangram.");
} else {
System.out.println("The sentence is NOT a Pangram.");
}
}
}