0

how to code this . sum of hashmap map.put("A",3); map.put("B",2); map.put("C",3); map.put("D",2); Enter : A Enter: B total : 5

30th Apr 2017, 12:36 AM
Ken Ben
Ken Ben - avatar
2 Respostas
+ 1
HashMap<String, Integer> map = new HashMap<>(); map.put("A",3); map.put("B",2); map.put("C",3); map.put("D",2); String input1 = "A"; //I simplified example with hardcoded strings, String input2 = "B"; //you can replace it with user input if you need. System.out.println("Total: " + (map.get(input1)+map.get(input2)));
30th Apr 2017, 12:46 AM
Jeth
Jeth - avatar
+ 1
thank u so much
30th Apr 2017, 12:52 AM
Ken Ben
Ken Ben - avatar