我已经编写了与明星指示相对应的代码。
// 2 points
static HashMap<String, Integer> Q1(ArrayList<String> inputList){
**// Return a HashMap containing all the input
Strings as keys with values equal to the length of each String**
String result = "";
for(String ch : inputList){
result = result + ch;
}
String strings = result;
int number = strings.length();
HashMap<String, Integer> x = new HashMap<String, Integer>();
x.put(strings,number);
return x;
这是输出
Incorrect on input: [challenge accepted, testing...]
Expected output : {challenge accepted=18, testing...=10}
Your output : {challenge acceptedtesting...=28}
正如您所看到的,由于某些原因,我的代码结合了字符串键并实际上添加了值。有没有办法将它们分开?