2021-09-26 17:26:59 +08:00
|
|
|
package Strings;
|
2020-08-27 00:01:50 +08:00
|
|
|
|
2020-10-24 18:23:28 +08:00
|
|
|
/** Wikipedia: https://en.wikipedia.org/wiki/Pangram */
|
2020-08-27 00:01:50 +08:00
|
|
|
public class Pangram {
|
|
|
|
|
2020-10-24 18:23:28 +08:00
|
|
|
/** Driver Code */
|
|
|
|
public static void main(String[] args) {
|
|
|
|
assert isPangram("The quick brown fox jumps over the lazy dog");
|
|
|
|
assert !isPangram("The quick brown fox jumps over the azy dog"); /* not exists l character */
|
|
|
|
}
|
2020-08-27 00:01:50 +08:00
|
|
|
|
2020-10-24 18:23:28 +08:00
|
|
|
/**
|
|
|
|
* Check if a string is a pangram string or not
|
|
|
|
*
|
|
|
|
* @param s string to check
|
|
|
|
* @return {@code true} if given string is pangram, otherwise {@code false}
|
|
|
|
*/
|
|
|
|
public static boolean isPangram(String s) {
|
|
|
|
boolean[] marked = new boolean[26]; /* by default all letters don't exists */
|
|
|
|
char[] values = s.toCharArray();
|
|
|
|
for (char value : values) {
|
|
|
|
if (Character.isLetter(value)) {
|
|
|
|
int index = Character.isUpperCase(value) ? value - 'A' : value - 'a';
|
|
|
|
marked[index] = true; /* mark current character exists */
|
|
|
|
}
|
|
|
|
}
|
2020-08-27 00:01:50 +08:00
|
|
|
|
2020-10-24 18:23:28 +08:00
|
|
|
for (boolean b : marked) {
|
|
|
|
if (!b) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-27 00:01:50 +08:00
|
|
|
}
|
2020-10-24 18:23:28 +08:00
|
|
|
return true;
|
|
|
|
}
|
2020-08-27 00:01:50 +08:00
|
|
|
}
|