如何记录变量中的最大值

How do I record the highest value in a variable

我有一个变量,我需要找到其中的最大值。该值不断变化。我需要将最高值放在文本字段中。

//这是完整的程序。发布代码无济于事。

我会尽量解释程序:

是正面还是反面。你按下两个按钮,正面和反面。还有一个组合 JTextField,它会在其中连续写入多少次,您就可以正确完成。 Combo JTextField 中的最高值我需要放入 Highscore JTextField。

只需为最大值添加另一个变量:

SomeType currentValue, maximumValue;

//Encapsulate currentValue and maximumValue
void setValue(SomeType value){
    currentValue = value;

    //update the maximum
    if(value.compareTo(maximumValue) > 0)
        maximumValue = value;
}

SomeType getMaximum(){
    return maximumValue;
}

SomeType getCurrent(){
    return currentValue;
}