top of page

Java Program to check whether given string is Pangram or Not?



What is Pangram?

A pangram is a sentence using every letter of a given alphabet at least once. Pangrams have been used to display typefaces, test equipment, and develop skills in handwriting, calligraphy, and keyboarding.


The following are examples of pangrams that are shorter than "The quick brown fox jumps over a lazy dog" (which has 33 letters) and use standard written English without abbreviations or proper nouns:

  • "Waltz, bad nymph, for quick jigs vex." (28 letters)

  • "Glib jocks quiz nymph to vex dwarf." (28 letters)

  • "Sphinx of black quartz, judge my vow." (29 letters)

  • "How quickly daft jumping zebras vex!" (30 letters)

  • "The five boxing wizards jump quickly." (31 letters)

  • "Jackdaws love my big sphinx of quartz." (31 letters)

  • "Pack my box with five dozen liquor jugs." (32 letters)


Code:

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");
		}
	}
}



Output:



Other Java Programs:



The Tech Platform

0 comments
bottom of page