简体   繁体   English

弄清楚if语句

[英]Figuring out if statement

So my project is about creating a table that adds statistic comparisons to a selection sort table. 因此,我的项目是创建一个将统计比较添加到选择排序表的表。 I've done the bulk of the work but am stuck at this one part that asks me to It should add "comparisons" to "totalComparisons". 我已经完成了大部分工作,但仍停留在要求我执行这一部分的工作上。它应该在“ totalComparisons”中添加“ comparisons”。 It should compare "comparisons" to "minComparisons" and set "minComparisons" to whichever is smaller. 它应该将“比较”与“ minComparisons”进行比较,并将“ minComparisons”设置为较小的一个。 It should also set "maxComparisons" in an analogous fashion. 它还应以类似方式设置“ maxComparisons”。 The words in quotes are variables. 引号中的单词是变量。 I know I need to write an if statement but I have no idea how to write it. 我知道我需要编写一个if语句,但是我不知道如何编写它。 Can somebody show me how to do the part where you compare "comparisons" to "minComparisons" and set "minComparisons" to whichever is smaller. 有人可以告诉我如何处理将“比较”与“ minComparisons”进行比较并将“ minComparisons”设置为较小的部分。

My code so far: 到目前为止,我的代码:

private static void endStatistics(){
    totalComparisons += comparisons; 
    if (comparisons ){

    }

thanks for any help. 谢谢你的帮助。

Try this: 尝试这个:

if(comparisons < minComparisons)
minComparisons = comparison;
    if (comparisons <=  minComparisons ){
        minComparisons = comparisons;
    }
    if (minComparisons <= comparisons ){
        minComparisons = minComparisons;
    }

You don't actually need the second if statement though, just to put it here to show you the whole picture. 您实际上并不需要第二个if语句,只需将其放在此处即可显示整个图片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM