问题
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);
and put it back
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.
I have seen this done before, but only when we have Integer count... then count++; this can then be returned to the hashtable!
回答1:
As per your question your Hashtable is like below.
Map <String , Float> complementaryColour=new Hashtable<String, Float >();
Try This
float f=(float) ((frequency/width*height)*total_distance);
lCount+=f;
来源:https://stackoverflow.com/questions/11541771/hash-table-map-updating-values