I'm having a little problem with a piece of homework I have to do... Its unlikely that I will get any help by tomorrow, but I'm posting this just on the offchance.
code:
public void findIt(String searchValue)
{
//Variable declaration
char currentChar;
int asciiValue = 0, hashTotal = 0, index = 0;
boolean found = false;
if (searchValue.length() != 3)
System.out.println("Error: the code must be three + characters long!");
else
{
//work out the hash total for each character in the code
for (int position = 0; position < searchValue.length(); position++)
{
//currentChar is set to the character in the index position
//being worked upon
currentChar = searchValue.charAt(position);
//the ASCII value of the character is found
asciiValue = (int)currentChar;
//the ASCII value is added to the hashTotal
hashTotal+= asciiValue;
}
//the hash code is worked out for the hashTotal
hashCode = hashTotal%hash.length;
if (hash[hashCode] == "free")
{
System.out.println("The requested code was not found.");
}
********** else if (hash[hashCode] == searchValue)
{
System.out.println("The requested code was found in index position "
+ hashCode + ".");
}
************
else
{
for (int indexPosition = 0; indexPosition < overflow.length; indexPosition++)
{
if (overflow[indexPosition] == searchValue)
{
found = true;
index = indexPosition;
System.out.println("found");
break;
}
}
if (found)
{
System.out.println("The requested code was found in index position "
+ (index + 51) + ".");
}
else
System.out.println("The requested code was not found.");
}
//reset hash total
hashTotal = 0;
}
}
[/QUOTE]Its part of a program to hash an array, and this is part of the method to search for a value entered in another class. (A three letter string). I have established that the program is working out the correct hash codes for the searched for variable. The problem seems to lie in the part between the asterisks. Everything else works fine. It just doesn't seem to realise that the string in hash[hashCode] is the same as searchedFor, but they are... without a shadow of doubt as far as I can see...
Have I just typed in the else if statement wrong or something? I'm going crazy here trying to figure it out [img]tongue.gif[/img]