Check Pangram

Check whether a sentence is a pangram (contains all letters A–Z).

IntermediateTopic: Module 4: String Programs
Back

Java Check Pangram Program

This program helps you to learn the fundamental structure and syntax of Java programming.

Try This Code
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a sentence: ");
        String s = sc.nextLine().toLowerCase();

        Set<Character> set = new HashSet<>();
        for (char c : s.toCharArray()) {
            if (c >= 'a' && c <= 'z') {
                set.add(c);
            }
        }

        if (set.size() == 26) {
            System.out.println("Pangram");
        } else {
            System.out.println("Not Pangram");
        }
        sc.close();
    }
}
Output
Enter a sentence: The quick brown fox jumps over the lazy dog
Pangram

Understanding Check Pangram

We collect all distinct letters and check if we have 26 of them.

Note: To write and run Java programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Java Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Java programs.

Table of Contents