ハッシュ テーブルを作成し、キーと値を出力するために列挙を使用しようとしています。コードをコンパイルしようとすると、ハッシュテーブルに入れた新しい double に「[」を入れる必要があるというコンパイル時エラーが発生し続けます。
コンパイル前: toys.put("Race Car", new double (29.99));
コンパイル時エラーは、次のように配置する必要があることを示しています。
toys.put("レースカー", new double [29.99]);
私は何を間違っていますか?
public static void main(String[] args) {
Hashtable toys = new Hashtable();
Enumeration toyName;
String getToyName;
double priceOfToy;
toys.put("Race Car", new double(29.99));
toys.put("Toy Bear", new double(15.99));
toys.put("Action Figure", new double(9.99));
//Show prices of each toy
toyName = toys.keys();
//Uses hasMoreElements method from enumeration to check what is in the hashtable
while (toyName.hasMoreElements()) {
//uses nextElement method from enumeration interface to
getToyName = (String) toyName.nextElement();
System.out.println(getToyName + "is now priced at " + toys.get(getToyName));
}
}