如何在变量中记录最高值 [英] How do I record the highest value in a variable

查看:92
本文介绍了如何在变量中记录最高值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量,我需要找到那里的最高值.该价值不断变化.我需要在文本框中输入最高的值.

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.

我将尝试解释该程序:

是头还是尾巴.您按下两个按钮,正面和反面.还有一个组合JTextField,它在其中连续写入了正确的次数.而我需要在Highscore JTextField中输入Combo JTextField中的最高值.

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.

推荐答案

只需添加另一个变量以达到最大值:

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

这篇关于如何在变量中记录最高值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆