有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java有人能解决这个hashmap问题吗?我甚至不知道这是什么意思

public class HashMap 
{
//need to add some code here but I don't know what

    private class MyHashMap<K,V> {
        MyHashMap() {
        }
        void put(K key , V value) {
       // find solution
        }

        V get(K key) {
            //how to return value from key?
            return null;
        }
       // find solution
    }

    public void doTestsPass()
    {
        int [][] testCases = {{1,2},{3,4},{5,6},{1,7},{1,8}};
        boolean passed = true;
        MyHashMap<Integer,Integer> map = new MyHashMap<>();

        for(int [] test: testCases){// find solution
            Integer key = test[0];
            Integer value = test[1];
            map.put(key,value);// find solution
            if(!value.equals(map.get(key))){
                System.out.println("Test failed["+key+","+value+"]"); 
                //need to find solution
                passed = false;
            }  
        }

        if(passed) {
            // find solution
            System.out.println("All tests passed");
        }
    }

    public static void main(String[] Args) { 
      // find solution
        new HashMap().doTestsPass();
    }
}

共 (0) 个答案