Wizard Alphabet

Wizard Alphabet
Java Program Help (loops and external file)?

Please help me with this program. I've been at it for hours … And I can not seem to get the correct commands in it … Thanks in advance and happy years NEW! A pangram is a sentence containing all the letters of the alphabet. Your task is to write a program that reads one sentence of text and determine whether it is a pangram. If the text is not a pangram print the missing letters. Sample Output: Text: Pack my box with five jars dozen liquor .– It is a pangram. The text: The five boxing wizards jump quickly .– It is a pangram. The text: Sympathizing would fix Quaker objectives .– It is a pangram. The text: How silly jumping zebras vex .– NOT a pangram. The missing letters: CKLQY

Addressing this problem one part at a time. First, to avoid confusion between lowercase and uppercase letters, first convert the entire sentence in capital letters. Say that his sentence was stored in the variable String 'prayer'. Let's make uppercaseand save 'mySentence. MySentence sentence.toUpperCase = (); We will solve this problem through a set. The special properties sets automatically removed any duplicates. So let's have all the characters of that string and put it in a set. This set contains then each thats USED point. To find the letters have disappeared, simply subtract the set of a complete set containing all the cards. Games come in various types, we will use a HashSet. To declare a HashSet, you must have the following lines: import java.utils .*; //<– this gives adequate public statements HashSet mySet = new HashSet () / / Now add our prayer in this series Collections.addAll (mySet, mySentence.toCharArray ()); Now, we also want one containing all the letters of the alphabet HashSet: public HashSet alphs = new HashSet () / / Now to add each letter Collections.addAll (alphs, "ABCDEFGHIJKLMNOPQRSTUVWXYZ". ToCharArray ()) Finally, subtract mySet Alpha: alphs.removeAll (mySet) / / alphs now holds all the cards are not used to finish … if (alphs.isEmpty ()) System.out.println ("Is a pangram") more for (char x: Alfa) System.out.println (x + "") That's it!

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*
*