打印屏幕:
Player13
Character Name: Fourz, Class Name: Ninja
Strength: 17, Agility: 21, Stamina: 17, Intellect: 25, Spirit: 20, Health: 52, Mana: 50
我只需要一个循环来检查我的 16 组不同的玩家统计数据并给出 100 的健康奖励。真的很难写一个正确的循环。
public static void sortPlayersByHealth() {
for (int outer = 0; outer < playerObjectArray.length -1; outer ++) {
for (int inner = 0; inner < playerObjectArray.length - 1; inner ++ ) {
int num1 = playerObjectArray[inner].gethealth();
//must + 1 for it to know to go to the next number and find the > number.
int num2 = playerObjectArray[inner+1].gethealth();
if(num1 > num2) {
Player Player = playerObjectArray[inner];
playerObjectArray[inner] = playerObjectArray[inner+1];
playerObjectArray[inner+1] = Player;
}
这是我之前编写的一个循环,用于帮助遍历所有 16 名球员的统计数据,并根据他们的健康评分从低到高对它们进行排序。非常感谢您更改此语法以将生命值增加 100 的任何帮助。
抱歉,如果这没有意义,我是编程新手,也是 stackoverflow 新手。