- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to Check Whether the Given String is Pangram
In this article, we will understand how to check whether the given string is pangram. A string is a pangram string if it contains all the character of the alphabets ignoring the case of the alphabets.
Below is a demonstration of the same −
Suppose our input is −
Input string: Abcdefghijklmnopqrstuvwxyz
The desired output would be −
Yes, the string is a pangram
Algorithm
Step 1 - START Step 2 - Declare a string value namely input_string. Step 3 - Define the values. Step 4 - Convert the input string to a character array. Step 5 - Iterate over the character of the array and check if the array contains all the alphabets using charAt(i) - 'a'. If yes, it’s a Pangram string. Step 6 - Display the result Step 7 - Stop
Example 1
Here, we bind all the operations together under the ‘main’ function.
public class Pangram { static int size = 26; static boolean isLetter(char ch) { if (!Character.isLetter(ch)) return false; return true; } public static void main(String args[]) { String input_string = "Abcdefghijklmnopqrstuvwxyz"; System.out.println("The string is defined as: " +input_string); int string_length = input_string.length(); input_string = input_string.toLowerCase(); boolean[] is_true = new boolean[size]; for (int i = 0; i < string_length; i++) { if (isLetter(input_string.charAt(i))) { int letter = input_string.charAt(i) - 'a'; is_true[letter] = true; } } boolean result; for (int i = 0; i < size; i++) { if (!is_true[i]) result = false; } result = true; if (result) System.out.println("\nYes, the string is a pangram"); else System.out.println("\nNo, the string is not a pangram"); } }
Output
The string is defined as: Abcdefghijklmnopqrstuvwxyz Yes, the string is a pangram
Example 2
Here, we encapsulate the operations into functions exhibiting object-oriented programming.
public class Pangram { static int size = 26; static boolean isLetter(char ch) { if (!Character.isLetter(ch)) return false; return true; } static boolean check_alphabets(String input_string, int string_length) { input_string = input_string.toLowerCase(); boolean[] is_true = new boolean[size]; for (int i = 0; i < string_length; i++) { if (isLetter(input_string.charAt(i))) { int letter = input_string.charAt(i) - 'a'; is_true[letter] = true; } } for (int i = 0; i < size; i++) { if (!is_true[i]) return false; } return true; } public static void main(String args[]) { String input_string = "Abcdefghijklmnopqrstuvwxyz"; System.out.println("The string is defined as: " +input_string); int string_length = input_string.length(); if (check_alphabets(input_string, string_length)) System.out.println("\nYes, the string is a pangram"); else System.out.println("\nNo, the string is not a pangram"); } }
Output
The string is defined as: Abcdefghijklmnopqrstuvwxyz Yes, the string is a pangram
- Related Articles
- Java program to check if string is pangram
- Python program to check if the given string is pangram
- Program to check given string is pangram or not in Python
- Python program to check if the string is pangram
- Program to check whether the sentence is pangram or not using Python
- Java program to check whether a given string is Heterogram or not
- C++ program to check whether given string is bad or not
- Java program to print whether the given string is a palindrome
- Java program to check whether the given number is an Armstrong number
- Python program to check whether a given string is Heterogram or not
- C# program to check whether a given string is Heterogram or not
- Java program to find whether the given string is empty or null
- Java Program to check whether one String is a rotation of another.
- Python program to check whether the string is Symmetrical or Palindrome
- Check whether the given string is a valid identifier in Python

Advertisements