Home > Back-end >  Novice to solve!!!!!
Novice to solve!!!!!

Time:02-22

The name and the Numbers below the subscript is one-to-one,
Xiao Ming 14, 15, little red xiao Ming 20... So on the corresponding down,
That is how to name add up all the same?
Such as come
Xiao Ming
The corresponding
14 + 20 + (12)=22,

CodePudding user response:

bosses kangkang me,

CodePudding user response:

 public static void main (String [] args) {
String [] test={" Ming ", "little red", "Ming", "xiao li", "little red", "Ming", "small class"};
Int [] money={14,15,20,40,70, - 12, 1};
Map The map=new HashMap<> (a);
for (int i=0; IThe String key=test [I];
Integer v=map. Get (key);
If (n==null) {
The map. The put (key, money [I]);
} else {
The map. The put (key, v + money [I]);
}
}
System. The out. Println (JSONUtil toJsonStr (map));
}

Results:
{" Ming ": 22," xiao li ": 40," little red ": 85," small class ": 1}
  • Related