Quadratic probing not working in insert function, HELP!!

I have code that reads in a file of words and inserts them into a index of the array based on their hash value. Now some words have the same hash value, such as "truck" and "lo" which are both in the file i have. The file is in alphabetical order, so it should put truck in table[11889] and when it gets to lo, the insert method should see that it is not null and it should quadratically put this in a null location, but its overwriting truck, so when i search for truck, it does not find it.
Here is the code:
import java.io.*;
public class HashTable {
private String[] table = new String[59999];
private int numentries;
static int i = 1;
static int j = 1;
public HashTable()
public int hashFunction(String w)
int slot = 1;
for(int i = 0; i < w.length();i++)
slot *= (int)w.charAt(i);
slot = slot%59999;
if(slot < 0)
slot +=59999;
return slot;
public boolean search(String w)
int value;
value = hashFunction(w);
if(value < 0)
value+= 59999;
if(table[value].equals(w))
return true;
else
while(value < 59999)
if(table[value].equals(w))
return true;     
value = (value + j * j)%59999;
if(value < 0)
value+= 59999;
j++;
return false;
public void insert(String w)
int value;
value = hashFunction(w);
if(value < 0)
value+= 59999;
if(table[value] == null)
table[value] = w;
else
while(table[value]!= null)
value = (value + i * i)%59999;
if(value < 0)
value+= 59999;
i++;
table[value] = w;
public static void main(String[] args) throws IOException
HashTable hashTable = new HashTable();
String word;
String file;
String check;
System.out.println("Welcome to the SpellChecker!");
System.out.println("Enter the name of your dictionary file.");
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
//file = input.readLine();
FileReader fr1 = new FileReader("c:\\general\\words.txt");
BufferedReader keyboard = new BufferedReader(fr1);
while((word = keyboard.readLine())!=null)
hashTable.insert(word);
keyboard.close();
System.out.println("Great, you dictionary has been stored in memory.");
System.out.println("What word would you like to check");
word = input.readLine();
if(hashTable.search(word))
System.out.println(word + " is a valid word in the dictionary");
else
System.out.println(word + " is not a valid word");
System.out.println("Would you like to check another word?");
check = input.readLine();
while(check.equals("yes"))
System.out.println("What word would you like to check?");
word = input.readLine();
if(hashTable.search(word))
System.out.println(word + " is a valid word in the dictionary");
else
System.out.println(word + " is not a valid word");
System.out.println("Would you like to check another word?");
check = input.readLine();
System.out.println("Thank you for using the SpellChecker!");
}

ok, i'm extremely new to java programming. I want to know more about hashtables and i've found that this was the best example i've found so far. Unfortunately there's no comments, in it, so i don't know what is going on in some places. For example, what is the method that is used to put the words into the table? how can you change it? Is there a special way that the words have to be put into the txt file? does it count periods and commas as a null space or does it count them as a character? aslo, when i run the program, i get the following runtime error:
Exception in thread "main" java.lang.NullPointerException
at HashTable.search(HashTable.java:45)
at HashTable.main(HashTable.java:119)
my code is exactly the same as up above except that i took out the static declaration in front of i and j, i commented out (not deleted) the j declaration, and put a new j declaration in the search method like this:
public boolean search(String w)
int j = 1; // <~~~~~this is the added line
int value
Please help

Similar Messages

  • Smart scan not working with Insert Select statements

    We have observed that smart scan is not working with insert select statements but works when select statements are execute alone.
    Can you please help us to explain this behavior?

    There is a specific exadata forum - you would do better to post the question there: Exadata
    I can't give you a definitive answer, but it's possible that this is simply a known limitation similar to the way that "Create table as select" won't run the select statement the same way as the basic select if it involves a distributed query.
    Regards
    Jonathan Lewis

  • I cannot get my messages/text messages to work om my Hi.  I am sending this thru my iPad.  Respond and let me know you got it.  Fun fun fun.  .  I did go and try to another Apple ID different from my iPhone but it still will not work.  Can anyone help me?

    I cannot get my messages/text messages to work om my Hi.  I am sending this thru my iPad.  Respond and let me know you got it.  Fun fun fun.  .  I did go and try to another Apple ID different from my iPhone but it still will not work.  Can anyone help me?

    chicx wrote:
    This is the third time of writing this on your Apple Support Communities!
    Not with your current user id.
    Far too much uneccesary information in your post, which only confuses things, a vast amount!
    Let's start with iTunes.
    Have you updated iTunes to 11.1.5, because the previous version did appear to have an issue about seeing iPods?
    With iTunes 11.1.5 installed, look in Edit/Preferences/Devices, (or use the ALT key, followed by the E key and then the F key) and make sure that the box named Prevent iPods, iPhones and iPads from syncing automatically does not have a tick in the box.
    Once you have doen those two things, check to see if the iPod is seen by iTunes.
    chicx wrote:
    By the way, what does IOS mean? (I thought IO stood for operating system, but am flummoxed by the S on the end.
    Really?
    OS stands for Operating System. (In computer speak, IO means Input/Output.)
    iOS originally stood for iPhone Operating System, but it now refers to the iPod Touch and iPhone. The iPod Classic, which you have listed in your profile as your iPod, does not use iOS.
    I assume that you have been listening to the Podcast in your iTunes on the computer as you cannot transfer it to your iPod. It's what I'd do.

  • On my macbook pro I have a message on my homepage telling me that certain items want to use my keychain. I've pressed cancel the message will not go. The mac is now running very slow and iphoto and safari are not working. Can anyone help?

    On my macbook pro I have a message on my homepage telling me that certain items want to use my keychain. I've pressed cancel the message will not go. The mac is now running very slow and iphoto and safari are not working. Can anyone help?

    What version of Mac OS X?
    What home page?
    What browser?

  • Bluetooth Driver In Windows 8.1 is Not Working after upgrading please help (pavilion g6 2008Tx)

    Bluetooth Driver In Windows 8.1 is Not Working after upgrading please help (pavilion g6 2008Tx)
    what cAN i do to make it work?please help

    Hi:
    If your model uses a Ralink wireless card, see if installing this bluetooth driver works.
    http://h20565.www2.hp.com/hpsc/swd/public/detail?swItemId=ob_135494_1

  • Hi, recently i bought macbook pro with retina display and installed windows 8 professional original software also. but in windows 8 track pad is not working properly. can you help me with providing drivers for trackpad to work on windows 8 professional .

    hi, recently i bought macbook pro with retina display and installed windows 8 professional original software also. but in windows 8 track pad/ TOUCHPAD is not working properly. can you help me with providing drivers for trackpad to work on windows 8 professional .

    Did you download and install the Windows Support software? If you did, did you use the Boot Camp Control icon to set up the trackpad how you want it?
    http://www.apple.com/support/bootcamp/
    https://discussions.apple.com/community/windows_software/boot_camp

  • Hello, the 'Save As' dialog box used to allow the backspace button to go up one level in the directory when the focus is in the folder contents box but it does not work any more, please help.

    Hello, the 'Save As' dialog box used to allow the backspace button to go up one level in the directory when the focus is in the folder contents box but it does not work any more, please help. BTW the same 'Save As' dialog in other applications still allow the backspace button to go up one level in the directory.

    cor-el,
    I kept forgetting and procrastinating about following your instructions, since I have internet access only for limited amounts of time and usually I am busy with important tasks when I am.
    Out of the blue, the problem corrected itself (the Save As box started to open full screen, then shrunk down to a normal size and the edges can now be dragged to a custom size).
    Even the copy and paste problem in the filenaming area seems to have been less troublesome lately even though there have been no updates to Firefox in a few weeks.
    Even though I marked the solution as not helpful, the problem has in fact been resolved. I will save the solution instructions in case the issue returns.

  • TS3297 I want to buy the double coins from the game subway surfers! But they told me to contact the itunes support! I don't know why it's not working.. Please help! iPhone 4ss

    I want to buy the double coins from the game subway surfers! But they told me to contact the itunes support! I don't know why it's not working.. Please help! iPhone 4ss

    These are user-to-user forums, you are not talking to Apple here. You can contact iTunes support via this page and ask them why the message is appearing : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then probably Purchases, Billing & Redemption

  • I recently downloaded iMovie on my iPhone 5 and it is telling me to connect to wifi or use itunes to download iMovie well I have done both and it is still not working can someone please help me?

    I recently downloaded iMovie on my iPhone 5 and it is telling me to connect to wifi or use itunes to download iMovie well I have done both and it is still not working can someone please help me?

    Hi troy157,
    I'm sorry you are having issues with the iMovie app you purchased for your iPhone5.
    The first thing I would suggest is to log out of your iTunes Account on your iPhone, turn the iPhone off and then on again, and see if app finishes downloading/updating.
    Settings > iTunes & App Stores > Tap on your Apple ID account > Tap Sign Out
    If the issues persists, the article below will give you a few more troubleshooting steps:
    iOS: Troubleshooting applications purchased from the App Store
    Try the following steps to resolve your issue, testing the app after each step.
    1. Update your device software
    Update your device to the latest version of iOS.
    2. Check for app updates
    Ensure that your apps are up to date:
    Open the App Store and tap Updates. If updates are available, tap Update All.
    When prompted, enter your iTunes Store account information. App Store will then download and install the application updates.
    Note: Some applications may require a Wi-Fi connection to update.3. Install another app from the App Store
    4. Restart the application
    If the issue affects only a single app, try closing just that app:
    Press the Home button to return to the Home screen.
    Double-tap the Home button to display recent apps.
    Tap and hold the affected app until the red minus appears.
    Tap the red minus to quit the app.
    Press the Home button, then restart the app.
    5. Restart your device
    Hold the Sleep/Wake button until "slide to power off" appears. Slide to power off your device. When it is off, press the Sleep/Wake button to turn it back on.6. Reinstall the affected application
    Remove the application from your device and reinstall it.
    Touch and hold any application icon on the Home Screen until the icons start to wiggle.
    Tap the "x" in the corner of the application you want to delete.
    Tap Delete to remove the application and all of its data from your device.
    Press the Home button.
    Go to the App Store.
    Search for the application and then download it again.
    Note: If it is a paid app, ensure you are using the iTunes account you purchased the app with originally. If it is not, you will be charged for the app again. For more information regarding downloading previously purchased items, see this article.
    I hope this information helps ....
    Have a great day!
    - Judy

  • Since installing Yosemite and Photos I can now no longer drag and drop a photo in an email, as I have always done. I repaired permission and restarted a number of times. still not working... Help?! Thanks, Michael

    Since installing Yosemite and Photos I can now no longer drag and drop a photo in an email, as I have always done. I repaired permission and restarted a number of times. still not working... Help?! Thanks, Michael

    What happens if you use the Share button and select Mail?
    What happens when you try? I had to hold there photo there for a short period before it would load.

  • U10i sony ericsson speaker not working...need help

    u10i sony ericsson speaker not working...need help...thanks

    Anyway thanks... Yesterday my handphone drop again,than the speaker suddenly recover.

  • Just now i replace the 5s mother board but could not work touch id pls help me.....

    just now i replace the 5s mother board but could not work touch id pls help me.....

    if you have replaced the logic board on your phone, by yourself then that is considered modification  and can cause other parts to fail due to ESD issues or just damage from handling parts

  • Brand new 15" MacBook Pro Retina - unplugged from Thunderbolt Display and Keyboards today find keyboard alpha-numerics not working; except the function keys, delete key, tab key, command/ctrl/shift/alt/fn and arrow keys; and 7/8/9/u/o/j/l nudge cursor

    Brand new 15" MacBook Pro Retina - unplugged from Thunderbolt Display and Keyboards today find keyboard alpha-numerics not working; except the function keys, delete key, tab key, command/ctrl/shift/alt/fn and arrow keys; and 7/8/9/u/o/j/l produce cursor nudges.

    It's a new machine - and the Thunderbolt Display is meant to work with it. You need to just make an appointment at your local Apple Store and have them fix whatever is wrong.
    If you like, you could always try a SMC reset and a PRAM/NVRAM reset to see if either of those will get your keyboard back in working order...
    Clinton

  • My factory unlocked iphone 4s mms is not working with tmobile, please help...

    my factory unlocked iphone 4s mms is not working with tmobile, please help...

    Check out this link. It should fix the problem
    http://support.t-mobile.com/thread/17918?tstart=0

  • HT3180 I just updated my Apple TV 2 and now it is flashing and not working at all.  Help

    I just updated my Apple TV 2 and now it is flashing and not working at all.  Help

    I just did the update to version 5.2 on our ATV2 and now I'm having the exact same problem as the OP- all attempts to access any iTunes services i.e. Movies or TV result in dropping back to the ATV Main menu.   Per Winston's suggestion, I logged out of iTunes and then tried to log back in.  I am getting a message "the server is not responding- please try again later".
    FWIW- all my non-iTunes services on the ATV are working fine- i.e. Netflix and YouTube.
    Sounds like the update has overwhelmed the Apple servers.
    Dave

Maybe you are looking for

  • PE 9 and 10 Help PDF Invalid List View Descriptions

    Bottom line: Has anyone reported on these problems, and, if so, what is being done about them? Until proven otherwise, I believe that Premiere Elements 9 and 10 Help PDF requires editing of its List View Descriptions which are appropriate for at leas

  • How can I group TV shows together??

    Hey guys, I've got a bit of an annoyance. Is there any way I can group my TV shows together, by show. So heres how I've got it now: http://img443.imageshack.us/img443/6848/itunestz.png I want to have it so they aren't grouped by season, they are grou

  • Counter in Project Siena

    How to make a counter (eg. if I press a button, value in a label will be increased by 1)

  • Weblogic patch for the "Authentication for user wlsadmin denied" issue

    Hi Everyone, When I try to login to the weblogic console using the weblogic user id and password, I got below issue in the production server..Sometime back I saw a thread that Oracle has provided a patch for this issue. If any of you is aware of it t

  • Illustrator 10 on Windows 7 PC

    I had Illustrator on a workstation running Windows XP Professional Service Pack 3. The OS crashed and I upgraded the workstation to Windows 7 Professional. I reinsallted Illustrator 10 and all seemed to go well - including activation.  When I go to r