您将如何编写代码让用户比较列表中的每首歌曲并返回播放次数最多的歌曲?另外,如果播放次数最多的歌曲不止一首,如何全部显示?
这是我到目前为止所拥有的:
case 5:
boolean max = false;
int mostPlays = 1;
song = new Song(artist,title);
for(int i = 0; i < songCollection.size(); i++)
{
song = songCollection.get(mostPlays);
if (songCollection.get(i).getNoPlays() < song.getNoPlays())
{
songCollection.get(mostPlays).getTitle();
mostPlays++;
max = true;
}
else
{
mostPlays++;
}
}
while (max)
{
System.out.println(song.getTitle());
}
break;