이 메서드는 가장 인기있는 친구를 반환합니다. 나는이 루프가 arraylist에 getFriend().size() > 0
을 가진 객체를 추가 할 것이라고 생각한다. 그런 다음 다음 객체 getFriend().size()
과 ArrayList에있는 객체를 비교합니다. Object가 더 많이 ArrayList에 추가되고 다른 객체는 더 많은 친구가 있으면 제거됩니다.내 foreach 루프가 작동하지 않습니다.
// Class variables
// the person's name
private String name;
// a list of this person's friends
private ArrayList<Person> friends;
public Person mostConnectedFriend(){
for(Person f : friends){
ArrayList<Integer> mostFriends = new ArrayList<>();
int amountOfFriends = 0;
if(getFriends().size() > amountOfFriends){
mostFriends.remove(amountOfFriends);
mostFriends.add(amountOfFriends);
}
} return null;
}
성취하려는 것은 무엇입니까? –
[ "does not work]"(http://importblogkit.com/2015/07/does-not-work/)이라고 생각하는 이유를 설명해 주시겠습니까? 이 코드에서 무엇을 기대했으며 대신 무엇을 얻었습니까? – Pshemo
대부분 "연결된"친구입니까? –