I'm trying a simple HashMap example. but i am getting some errors i have listed below. I am totally new to this. please help
The code is as follows.
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class MainClass {
public static void main(String args[]) {
HashMap<String, Double> hm = new HashMap<String, Double>();
hm.put("A", new Double(3434.34));
hm.put("B", new Double(123.22));
hm.put("C", new Double(1378.00));
hm.put("D", new Double(99.22));
hm.put("E", new Double(-19.08));
Set<Map.Entry<String, Double>> set = hm.entrySet();
for (Map.Entry<String, Double> me : set) {
System.out.print(me.getKey() + ": ");
System.out.println(me.getValue());
}
System.out.println();
double balance = hm.get("B");
hm.put("B", balance + 1000);
System.out.println("B's new balance: " + hm.get("B"));
}
}
ERRORS::
C:\trainee>javac MainClass.java
MainClass.java:8: not a statement
HashMap<String, Double> hm = new HashMap<String, Double>();
^
MainClass.java:8: ';' expected
HashMap<String, Double> hm = new HashMap<String, Double>();
^
MainClass.java:16: not a statement
Set<Map.Entry<String, Double>> set = hm.entrySet();
^
MainClass.java:16: ';' expected
Set<Map.Entry<String, Double>> set = hm.entrySet();
^
MainClass.java:18: not a statement
for (Map.Entry<String, Double> me : set) {
^
MainClass.java:18: not a statement
for (Map.Entry<String, Double> me : set) {
^
MainClass.java:18: ';' expected
for (Map.Entry<String, Double> me : set) {
^
MainClass.java:25: '.class' expected
double balance = hm.get("B");
^
MainClass.java:26: ')' expected
hm.put("B", balance + 1000);
^