What is Pangram?
Pangram is a unique sentence in which every letter of the alphabet is used at least once. The name comes from the Greek root words pan, meaning 'all' and gram, meaning 'something written or recorded'.
An English Pangram is a sentence that contains all 26 letters of the English alphabet (a-z or A-Z).
Every letter of the alphabet sentence as shown in the below example.
Examples for Pangram:
1. "The quick Brown fox jumps Over a Lazy Dog."
2. "Amazingly few discotheques provide jukeboxes."
Java code to check if the string is Pangram or Not :
import java.util.Scanner;
public class Programming9 {
public static void main(String args[]){
//Scanner is a class which read input from keyboard
Scanner sc=new Scanner(System.in);
System.out.println("Enter Your String:");
//to read string end of line
String str=sc.nextLine();
// replaceALL()-->replaces all spaces between strings
//toLowerCase()->method which converts all characters to lower case
str=str.replaceAll("","").toLowerCase();
// empty string
String s="";
// checking characters (a-z or A-Z)
for(char i='a';i<='z';i++){
//indexOf(char i)--> This method returns '-1' substring not found, if the position of substrings 'i' in 'str'
if(str.indexOf(i)!=-1){
s=s+i;// empty string+character
}
}
// s.length()-->this method returns number or character of a string
if(s.length()==26){
System.out.println("Pangram");
}
else{
System.out.println(" Not Pangram");
}
}
}
Test Cases to Check Given String is a Pangram
Enter a String: The quick Brown fox jumps over a Lazy Dog Pangram
Enter a String: The five boxing wizards jumps quickly Pangram
Enter a String: the dog is roaming in the street Not Pangram