Pangrammatic Lipogram Java Program | ISC Computer Science Sample Paper 2026

Write a program to accept a sentence which may be terminated by either ‘.’, ‘?’ or ‘!’ only. The words may be separated by a single blank space and should be case-insensitive.

Perform the following tasks:
a) If the sentence is a pangram (a sentence or a phrase that uses every letter of the alphabet at least once), then print PANGRAM.
b) If it misses exactly one letter of the alphabet, print PANGRAMMATIC LIPOGRAM and the missing letter.
c) Else print NEITHER and list all the missing letters in alphabetical order.

Test your program for the following data and some random data:

Example 1
INPUT: The quick brown fox jumps over the lazy dog!
OUTPUT: IT IS A PANGRAM

Example 2
INPUT: A quick movement of the enemy will jeopardize bright fawns.
OUTPUT:
PANGRAMMATIC LIPOGRAM
Missing: x

Example 3
INPUT: Hello world!
OUTPUT:
NEITHER
a b c f g i j k m n p q s t u v x y z

Example 4
INPUT: Alas! it failed #
OUTPUT: INVALID INPUT

import java.util.Scanner;
class Pangram{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.print("Sentence: ");
        String s = in.nextLine().toLowerCase();
        char last = s.charAt(s.length() - 1);
        if(".?!".indexOf(last) == -1){
            System.out.println("INVALID INPUT");
            return;
        }
        int missing = 0;
        String m = "";
        for(char ch = 'a'; ch <= 'z'; ch++){
            if(s.indexOf(ch) == -1){
                missing++;
                m += ch + " ";
            }
        }
        if(missing == 0)
            System.out.println("IT IS A PANGRAM");
        else if(missing == 1){
            System.out.println("PANGRAMMATIC LIPOGRAM");
            System.out.println("Missing: " + m);
        }
        else{
            System.out.println("NEITHER");
            System.out.println("Missing: " + m);
        }
    }
}