我不确定这行Java代码的作用。

huangapple go评论74阅读模式
英文:

I'm not sure what this java row does

问题

int iEnd = i == grid.length - 1 ? 0 : 1;

英文:

I should probably know that but I'm not sure what this line of code is doing:

int iEnd=i==grid.length - 1 ? 0:1;

答案1

得分: 0

它将在i等于grind.length - 1时将iEnd设置为0,否则将iEnd设置为1。

这个操作符被称为“三元运算符”,是“条件运算符”的简写形式,你可以在这里阅读更多关于它的信息:https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

英文:

it will set iEnd to 0 if i equals grind.length -1 otherwise it will set iEnd to 1

the operator is called Ternary Operator and is a short hand for a Conditional Operator
and you can read more about it here: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html

huangapple
  • 本文由 发表于 2020年5月29日 04:45:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/62074223.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定