Friday, September 22, 2017

Find the sentance is pangrams or not using java?

First Pangrams explanation:
 
Pangrams are sentences constructed by using every letter of the alphabet at least once.


 Here is java code to find the pangrams,


private static void findPangrams(String p_sSentance) {
        Set<Character> l_objSet = new HashSet<Character>();
        int l_iLength = p_sSentance.length();
        while(l_iLength > 0)
        {
            if(p_sSentance.charAt(l_iLength-1) != ' '){
            l_objSet.add(p_sSentance.charAt(l_iLength-1));
            }
            l_iLength--;
        }
        if(l_objSet.size() == 26)
        {
            System.out.println("Pangram");
        }else{
            System.out.println("Not pangram");
        }
    }

Input 1 : "Pack my box with five dozen liquor jugs"
Input 2 : "Pack my box with five liquor jugs"

Output 1 :  Pangram
Output 2 :  Not pangram


No comments:

Post a Comment