How do I record the highest value in a variable [closed]

北慕城南 提交于 2020-01-24 02:12:20

问题


I have a variable and I need to find the highest value that was there. That value constantly changes. I need to put that highest value in a textfield.

//This is full program. Posting the code won't help.

I will try to explain the program:

It's Heads or Tails. You press two buttons, heads and tails. And there is a combo JTextField, where it writes how many times in a row you get it right. And the highest value that was in Combo JTextField I need to put in the Highscore JTextField.


回答1:


Just add another variable for the maximum:

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;
}


来源:https://stackoverflow.com/questions/31760854/how-do-i-record-the-highest-value-in-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!