gpt4 book ai didi

java - 如何获取列表的多个页面?

转载 作者:行者123 更新时间:2023-12-02 02:52:31 28 4
gpt4 key购买 nike

所以我正在开发一个 spigot 插件。这是关于 friend 的。如果这个人执行命令查看他的 friend 列表,我需要有页面,每个页面包含 7 个 friend 。问题是,它并不是一个 friend 列表,其中的 friend 列表中的人总是与您的 friend 列表发生变化的人相同。

案例我有 10 个 friend 。我会在第一页上看到 7 个 friend ,在第二页上看到剩下的 3 个 friend 。案例我有70个 friend 。我会有 10 页。

编辑:抱歉造成困惑。我的问题是:我怎样才能让它像例子中那样。玩家执行/friend list 时会显示第 1 页,其中有 7 个 friend 或更少(如果他没有 7 个 friend )。如果他有更多 friend ,则会显示第二页:/friend list 2。依此类推。

最佳答案

这是如何计算需要多少页的代码。它在 95% 的时间里有效,如果有人知道更好的解决方案,请编辑它,因为我也在寻求改进这个算法。

int friendsPerPage = 5;
int friendsIHave = 20;

int pages = (friendsIHave / friendsPerPage ) + (friendsIHave % friendsPerPage == 0 ? 0 : 1);

我假设您知道如何获取/ friend 列表(LISTHERE)。让我们将 LISTHERE 存储到页面变量中。然后我们可以简单地打印出它的内容:

int page = ... // you have to make this one
int max = page * friendsPerPage;
int min = max - friendsPerPage;
for(int i = min + 1; i <= max; i++) { // loop through all friends in that page
// access your friend array here and print it out using "i"
}

希望它能让您走上正轨!

关于java - 如何获取列表的多个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43592701/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com