public class nrlSports {
public static void main(String[] args){
String[] direction = {"north", "north", "east", "south", "south", "south", "north", "north"};
for(int i=0; i<direction.length; i++) {
int count = 0;
for(int j = 0; j < direction.length; j++)
if(direction[i].equals(direction[j])) {
count++;
}
System.out.println(direction[i] + " (" + count + ")");
}
}
}
输出为:北(4)北(4)东(1)南(3)南(3)南(3)北(4)北(4)
如何删除这些重复值,使输出应如下所示:北 (4) 东 (1) 南 (3)