Problem: Write a Java program to check whether the sentence or string is Pangram or not.

Example:

A pangram or holoalphabetic sentence is a sentence using every letter of a given alphabet at least once. The best-known English pangram is “The quick brown fox jumps over the lazy dog“.

Wikipedia

A sentence or word is called a pangram if it contains all 26 letters of the English alphabet.

To check if a string is a pangram, we need to verify whether it contains all the English alphabets.

In Java, we can easily do so by counting the frequency of each letter in the given string.

For this, we loop through the characters of the given string and store the frequency of letters in an array of size 26 (each index of the array will represent an English alphabet and the corresponding value, its frequency in the given string).

Pangram check using array

If all the elements in the array are greater than 0, then the string can be verified as a pangram string otherwise not.

Output:

Enter a sentence/string:
The quick brown fox jumps over the lazy dog
Pangram

Leave a Reply

4 × 3 =