哈希表映射-更新值 [英] Hash Table Map - updating values
问题描述
我只是使用哈希表来记住图像中出现哪些互补色.
I am just using a hash table to remember which complementary colours appear in an image.
无论如何,我得到了当前值计数:
Anyway so I get the current value count:
Float count = complementaryColour.get(complementaryString[1] + " and " + colourName);
现在我想更改计数,所以我这样做:
and now I want to change count, so I do:
count += (Float)((frequency/width*height)*total_distance);
放回去
complementaryColour.put(complementaryString[1] + " and " + colourName, count);
可悲的是,它不喜欢这样!它说我需要创建一个浮点数,然后查看将其放回哈希表中的那一行,它说它无法解析为变量.
Yet sadly it doesn't like this! It says I need to create a float count, and then when I look at the line putting it back in the hashtable it says it cannot be resolved to a variable.
我以前看过这件事,但是只有当我们有Integer count ...然后count ++时才可以完成;然后可以将其返回到哈希表!
I have seen this done before, but only when we have Integer count... then count++; this can then be returned to the hashtable!
推荐答案
根据您的问题,您的Hashtable
如下所示.
As per your question your Hashtable
is like below.
Map <String , Float> complementaryColour=new Hashtable<String, Float >();
尝试
float f=(float) ((frequency/width*height)*total_distance);
lCount+=f;
这篇关于哈希表映射-更新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!