-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPangramCheck.java
More file actions
27 lines (24 loc) · 818 Bytes
/
PangramCheck.java
File metadata and controls
27 lines (24 loc) · 818 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
// 46. Write a program to check if a given string is a pangram.
import java.util.HashSet;
import java.util.Set;
public class PangramCheck {
public static void main(String[] args) {
String str = "The quick brown fox jumps over the lazy dog";
boolean isPangram = isPangram(str);
if (isPangram) {
System.out.println("The string is a pangram.");
} else {
System.out.println("The string is not a pangram.");
}
}
public static boolean isPangram(String str) {
str = str.toLowerCase();
Set<Character> set = new HashSet<>();
for (char ch : str.toCharArray()) {
if (Character.isLetter(ch)) {
set.add(ch);
}
}
return set.size() == 26;
}
}