Menu
Question Index
...

Write a program to calculate the sum of the values from the given input by using one of the Map interface methods.

Input (Map) Output (Integer)
{A=1, B=2, C=3, D=4, E=5} 15
{Red=-12, Yellow=22, Blue=55, White=33, Green=44} 142
{Book=-1, Pen=2, Pencil=-3, Scale=4} 2
null null


import java.util.*;
class SumOfValues
{
    public static void main(String s[])
    {
        Map<String, Integer> input = new WeakHashMap<String, Integer>();
        input.put("A", 1);
        input.put("B", 2);
        input.put("C", 3);
        input.put("D", 4);
        input.put("E", 5);
        System.out.println("The sum of the values is : " + sumOfValues(input));

    }


    public static Integer sumOfValues(Map<String, Integer> input) {
    }

}

Doubts

Problems

Topic: Java WeakHashMap Class

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App