The Program wont run I just gave up PLEASE HELP
what i've done wrong???
on this line down it says cannot find symbol:
private static HashSet<Character> vowels = new HashSet<Character>();
here's the code:
Expand|Select|Wrap|Line Numbers
- public class TextAnalyzer {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.print(" Enter Text: ");
- String text = in.nextLine().toLowerCase();
- int vowels = 0, consonants = 0, spaces = 0, numbers = 0, punctuation = 0;
- for (int i = 0; i < text.length(); i++) {
- Character c = text.charAt(i);
- if (isVowel(c)) {
- vowels++;
- } else if (isConsonant(c)) {
- consonants++;
- } else if (Character.isWhitespace(c)) {
- spaces++;
- } else if (Character.isDigit(c)) {
- numbers++;
- } else if (isPunctuation(c)) {
- punctuation++;
- }
- }
- System.out.println("Number of Printable Characters is: "+ (text.length() + punctuation));
- System.out.println("Number of Vowels is: " + vowels);
- System.out.println("Number of Consonants is: " + consonants);
- System.out.println("Number of white spaces is: " + spaces);
- System.out.println("Number of digits is: " + numbers);
- }
- private static HashSet<Character> vowels = new HashSet<Character>();
- private static HashSet<Character> consonants = new HashSet<Character>();
- static {
- vowels.add('a');
- vowels.add('e');
- vowels.add('i');
- vowels.add('o');
- vowels.add('u');
- consonants.add('b');
- consonants.add('c');
- consonants.add('d');
- consonants.add('f');
- consonants.add('g');
- consonants.add('h');
- consonants.add('j');
- consonants.add('k');
- consonants.add('l');
- consonants.add('m');
- consonants.add('n');
- consonants.add('p');
- consonants.add('q');
- consonants.add('r');
- consonants.add('s');
- consonants.add('t');
- consonants.add('v');
- consonants.add('w');
- consonants.add('x');
- consonants.add('y');
- consonants.add('z');
- }
- private static boolean isPunctuation(Character c) {
- return c==',' || c=='.' || c=='!' || c=='?';
- }
- private static boolean isConsonant(Character c) {
- return consonants.contains(c);
- }
- private static boolean isVowel(Character c) {
- return vowels.contains(c);
- }
- }