473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Hash tables

Hello everyone,
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
  1. public class TextAnalyzer {
  2. public static void main(String[] args) {
  3. Scanner in = new Scanner(System.in);
  4. System.out.print(" Enter Text: ");
  5. String text = in.nextLine().toLowerCase();
  6.  
  7. int vowels = 0, consonants = 0, spaces = 0, numbers = 0, punctuation = 0;
  8. for (int i = 0; i < text.length(); i++) {
  9.  
  10. Character c = text.charAt(i);
  11. if (isVowel(c)) {
  12. vowels++;
  13. } else if (isConsonant(c)) {
  14. consonants++;
  15. } else if (Character.isWhitespace(c)) {
  16. spaces++;
  17. } else if (Character.isDigit(c)) {
  18. numbers++;
  19. } else if (isPunctuation(c)) {
  20. punctuation++;
  21. }
  22. }
  23. System.out.println("Number of Printable Characters is: "+ (text.length() + punctuation));
  24. System.out.println("Number of Vowels is: " + vowels);
  25. System.out.println("Number of Consonants is: " + consonants);
  26. System.out.println("Number of white spaces is: " + spaces);
  27. System.out.println("Number of digits is: " + numbers);
  28. }
  29.  
  30.  
  31. private static HashSet<Character> vowels = new HashSet<Character>();
  32.  
  33. private static HashSet<Character> consonants = new HashSet<Character>();
  34.  
  35.  
  36. static {
  37.  
  38. vowels.add('a');
  39. vowels.add('e');
  40. vowels.add('i');
  41. vowels.add('o');
  42. vowels.add('u');
  43. consonants.add('b');
  44. consonants.add('c');
  45. consonants.add('d');
  46. consonants.add('f');
  47. consonants.add('g');
  48. consonants.add('h');
  49. consonants.add('j');
  50. consonants.add('k');
  51. consonants.add('l');
  52. consonants.add('m');
  53. consonants.add('n');
  54. consonants.add('p');
  55. consonants.add('q');
  56. consonants.add('r');
  57. consonants.add('s');
  58. consonants.add('t');
  59. consonants.add('v');
  60. consonants.add('w');
  61. consonants.add('x');
  62. consonants.add('y');
  63. consonants.add('z');
  64. }
  65.  
  66. private static boolean isPunctuation(Character c) {
  67. return c==',' || c=='.' || c=='!' || c=='?';
  68. }
  69.  
  70.  
  71. private static boolean isConsonant(Character c) {
  72. return consonants.contains(c);
  73. }
  74.  
  75. private static boolean isVowel(Character c) {
  76. return vowels.contains(c);
  77. }
  78. }
Aug 14 '08 #1
4 1633
Laharl
849 Expert 512MB
Did you import java.util.HashSet?
Aug 14 '08 #2
JosAH
11,448 Expert 8TB
Hello everyone,
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>();
Normally your friendly Java compiler displays a little caret character just
underneath the offending token which, in your case, is the symbol that wasn't
found by the compiler; in the error diagnostic message itself the compiler also
mentions that symbol explicitly. If you happen to receive such messages from
the compiler please copy/paste them here verbatim instead of just mentioning
some vague indication of what exactly the compiler told you.

kind regards,

Jos
Aug 14 '08 #3
Did you import java.util.HashSet?
yeah actually so stupid silly mistake :X I saw that right away i posted this :D
but nvm thank you for the help
Aug 14 '08 #4
You should import java.util.HashSet and see how it goes
Aug 18 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Pelo GANDO | last post by:
Hi everybody ! I am a beginner in C++. I am looking for a (simple if it's possible) source code in C++ about hash table... Thank you ! Pelo
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
12
by: wxs | last post by:
Many times we have a bunch of enums we have from either different enums or the same enum that will have various numeric values assigned. Rarely will there be collisions in numbering between the...
2
by: Ravi | last post by:
Hi, I am working on a winform app. I need to use an object which can store some information(key/value pairs) and also can be acessed by multiple threads(read/write). From what I heard Hash table...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
12
by: shaanxxx | last post by:
I wanted to write hash function float or double. Any suggestion would be appreciated.
6
by: fdmfdmfdm | last post by:
This might not be the best place to post this topic, but I assume most of the experts in C shall know this. This is an interview question. My answer is: hash table gives you O(1) searching but...
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
1
by: jacob navia | last post by:
Everybody knows that hash tables are fast. What is less known is that perfect hash tables are even faster. A perfect hash table has a hash function and a table layout that avoids collisions...
23
by: raylopez99 | last post by:
A quick sanity check, and I think I am correct, but just to make sure: if you have a bunch of objects that are very much like one another you can uniquely track them simply by using an ArrayList...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.