gpt4 book ai didi

java - 如何跟踪java中的高分?

转载 作者:行者123 更新时间:2023-11-29 07:36:56 26 4
gpt4 key购买 nike

Java 程序的目的是在您每次按下按钮时选择一个 0 到 11 之间的随机整数(含 0 到 11)。如果整数为 1 或 2,则总计为 0。否则将整数添加到运行总计中。我已经完成了所有这些,但我不知道如何更新高分(它应该在达到更高分数时更新)。

public void update() { 
int value = ((int)(Math.random() * (11 - 1 + 1) + 1));
label1.setText("Value: " + value);

if (value < 3) {
total = 0;
} else {
total = value + total;
}

label2.setText("Total: " + total);

if (highScore <= total) {
label3.setText("High Score: " + highScore);
}
}

但我知道最后一部分不会起作用,因为我还没有对变量 highScore 做任何事情。

最佳答案

if(highScore < total) 
{
highScore = total;
label3.setText("High Score: " + highScore);
}

请注意,我认为您想要 < 而不是 <=

关于java - 如何跟踪java中的高分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34549135/

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