Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从列表中吐出播放次数最多的歌曲_Java_Arrays_For Loop_Arraylist_While Loop - Fatal编程技术网

Java 从列表中吐出播放次数最多的歌曲

Java 从列表中吐出播放次数最多的歌曲,java,arrays,for-loop,arraylist,while-loop,Java,Arrays,For Loop,Arraylist,While Loop,您将如何编写一个代码,允许用户比较列表中的每首歌曲并返回主要播放的歌曲?此外,如果有多首歌曲的播放次数最多,如何显示所有歌曲 以下是我目前掌握的情况: case 5: boolean max = false; int mostPlays = 1; song = new Song(artist,title); for(int i = 0; i < songCollection.size(); i++) {

您将如何编写一个代码,允许用户比较列表中的每首歌曲并返回主要播放的歌曲?此外,如果有多首歌曲的播放次数最多,如何显示所有歌曲

以下是我目前掌握的情况:

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;
按播放次数按降序排列列表。 从开头开始,显示歌曲,保存播放次数。 转到下一首歌曲,如果播放次数相同则显示,如果不相同则停止。重复 相关文件:

用于分类