我有下面的方法来获取在双散列类中输入的键的值。运行后一直说有错误。
/* Function to get value of a key */
public int get(String key)
{
int hash1 = myhash1( key );
int hash2 = myhash2( key );
while (table[hash1] != null && !table[hash1].key.equals(key))
{
hash1 += hash2;
hash1 %= TABLE_SIZE;
}
return table[hash1].value;
}
首先,我必须在哈希表中插入一个新的名称和值,如果之后我有示例,则可以正常工作:
System.out.println( "Please enter the name of the person you want to search for: " );
System.out.println( "Value= " + ht.get(scan.next()));
但如果我有:
System.out.println( "Please enter the name of the person you want to search for: " );
System.out.println( "Value= " + ht.get(scan.nextLine()));
它说有一个错误。这意味着该方法不接受包含空格等的整行字符串,但它只接受单个字符串。Netbeans 说错误在于这一行:
return table[hash1].value;
谁能帮我?