java代码中的问号 [英] Question mark in java code
本文介绍了java代码中的问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以在下面的代码中解释问号吗?此外,INITIAL_PERMANCE是代码中的静态最终常量,但synatax的最后一行是什么?
Can someone explain the question mark in the following code? Also INITIAL_PERMANCE is a static final constant in the code but what is the last line of synatax called?
Synapse(AbstractCell inputSource, float permanence) {
_inputSource = inputSource;
_permanence = permanence==0.0 ?
INITIAL_PERMANENCE : (float)Math.min(1.0,permanence);
}
推荐答案
?和:是java条件运算符的一部分。有时称为三元运算符,因为它是Java中唯一带有3个参数的运算符。
The ? and : are part of the java conditional operator. Sometimes called the ternary operator because it is the only operator in Java that takes 3 arguments.
这实际上是一个内联IF / THEN / ELSE块。
This is essentially an inline IF / THEN / ELSE block.
_permanence = permanence==0.0 ?
INITIAL_PERMANENCE : (float)Math.min(1.0,permanence);
可以按如下方式重写:
if (permanence == 0.0)
_permanence = INITIAL_PERMANENCE;
else
_permanence = (float) Math.min(1.0,permanence);
条件运算符的一般形式是
The general form of the conditional operator is
<Test returning a boolean> ? <value for if test is true> : <value for if test is false>
这篇关于java代码中的问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文