Thursday 5 November 2015

Java program to check if given String is Pangram or not


A pangram or holoalphabetic sentence for a given alphabet is a sentence using every letter of the alphabet at least once.

For Example:-
  • We promptly judged antique ivory buckles for the next prize.
  • How razorback jumping frogs can level six piqued gymnasts.
  • Sixty zippers were quickly picked from the woven jute bag.
  • Crazy Fredrick bought many very exquisite opal jewels.
  • Jump by vow of quick, lazy strength in Oxford.
  • The quick brown fox jumps over the lazy dog.

Sample Program:-


 /**  
  * @author Dixit  
  *   
  */  
 public class PangramExample {  
      /**  
       * @param args  
       */  
      public static void main(String[] args) {  
           String s = "The quick brown fox jumps over the lazy dog";  
           System.out.println("Is given String Pangram ? : "  
                     + isPangramString(s.toLowerCase()));  
      }  
      private static boolean isPangramString(String s) {  
           if (s.length() < 26)  
                return false;  
           else {  
                for (char ch = 'a'; ch <= 'z'; ch++) {  
                     if (s.indexOf(ch) < 0) {  
                          return false;  
                     }  
                }  
           }  
           return true;  
      }  
 }  


Output:-

 Is given String Pangram ? : true  


Enjoy Programming.

No comments:

Post a Comment