小编Oyu*_*iry的帖子

有人可以向我解释一下哨兵在Java中的作用吗?或者它是如何工作的?

我试图了解哨兵是什么或它如何与该计划一起工作.无论如何,这是我想要了解的代码块.我知道这是一个哨兵控制循环,但我不知道它是做什么的.

private static final int SENTINEL = -999
Run Code Online (Sandbox Code Playgroud)

据我所知,通过使用负整数表示序列的结束.但它是如何做到的呢?哦,我该如何初始化哨兵?它已经初始化了吗?

public static int gameScore(int[] teamBoxScore) { //This is telling me the name of an array
int output = 0;
for (int v : teamBoxScore){ //I know that this the values of the array will be stored in the variable "v".
     if (v !=SENTIENL) {// 
         output += v; 
      }
}
return output;
} 
Run Code Online (Sandbox Code Playgroud)

谢谢,麻烦您了!我正在学习如何用Java编写代码

java sentinel

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×1

sentinel ×1