英文:
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
专注分享java语言的经验与见解,让所有开发者获益!
评论