Ask Question

Given a string check if it is Pangram or not. A pangram is a sentence containing every letter in the English Alphabet.

+2
Answers (1)
  1. 6 July, 02:11
    0
    Here is code in java.

    import java. util.*;

    class Main

    {/ / main method of the class

    public static void main (String[] args) throws java. lang. Exception

    {

    try{

    //scanner class object to read input

    Scanner in=new Scanner (System. in);

    String inp_str;

    / / array to keep count of all alphabets

    int[] arr = new int[26];

    int j=0;

    int flag=1;

    System. out. println ("Enter the String:");

    / / read input

    inp_str=in. nextLine ();

    / / find length of the string input

    int len=inp_str. length ();

    / / increase the count of each alphabet

    for (int i=0; i
    {

    if ('A' < = inp_str. charAt (i) && inp_str. charAt (i) < = 'Z')

    {

    j = inp_str. charAt (i) - 'A';

    }

    else if ('a' < = inp_str. charAt (i) && inp_str. charAt (i) < = 'z')

    {

    j = inp_str. charAt (i) - 'a';

    }

    arr[j] = arr[j]+1;

    }

    / / check if count of any alphabet is 0

    for (int i=0; i<26; i++)

    {

    if (arr[i]==0)

    {

    flag=0;

    break;

    }

    }

    / / print the output

    if (flag==1)

    {

    System. out. println ("String is pangram.");

    }

    else

    {

    System. out. println ("String is not pangram.");

    }

    }catch (Exception ex) {

    return; }

    }

    }

    Explanation:

    Read the string from user. Create an array "arr[26]" of size to keep count of each character. Travers all the string and if a character is present then increase the count corresponding to that character in the array. After this if there is count of any character is 0 then print not pangram else print string is pangram.

    Output:

    Enter the String:

    hello world welcome to java String is not pangram.

    Enter the String:

    The quick brown fox jumps over the lazy dog String is pangram.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Given a string check if it is Pangram or not. A pangram is a sentence containing every letter in the English Alphabet. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers