-
Notifications
You must be signed in to change notification settings - Fork 3
/
Pangrams.java
31 lines (26 loc) · 969 Bytes
/
Pangrams.java
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
// https://www.hackerrank.com/challenges/pangrams/problem
package strings;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Pangrams {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String string = scanner.nextLine();
System.out.println(isPangram(string) ? "pangram" : "not pangram");
}
private static boolean isPangram(String string) {
Set<Character> letters = getLetters(string);
return letters.size() == 26;
}
private static Set<Character> getLetters(String string) {
Set<Character> letters = new HashSet<>();
for (int index = 0 ; index < string.length() ; index++) {
char character = string.charAt(index);
if (Character.isAlphabetic(character) && character != ' ') {
letters.add(Character.toLowerCase(character));
}
}
return letters;
}
}