什么""和":"在布尔语句呢? [英] What does "?" and ":" do in boolean statements?
问题描述
我认为这个问题是一个普遍的编程的问题,
但让我们假设我问这对Java。
I think this question is a general programming question, but let's assume I'm asking this for Java.
什么下面的语句呢?
return a ? (b || c) : (b && c);
我已经看到了
的语法和:
'?的很多话题在SO,这个特殊的一个我在<已找到href=\"http://stackoverflow.com/questions/3076078/check-if-at-least-two-out-of-three-booleans-are-true\">Check如果至少有三分之二的布尔是真实
I have seen the syntax with ?
's and :
's in many topics at SO, this particular one I found in Check if at least two out of three booleans are true
但我不知道他们的意思,因此,如何使用它们,而且我相信这是非常有用的东西给我。
But I don't know what they mean, so how to use them, and I believe it's something very useful for me.
谢谢!
推荐答案
这是有条件的经营者。这意味着是这样的:
That's the conditional operator. It means something like:
condition ? value-if-true : value-if-false;
所以你的情况,它返回 B || ç
如果 A
是真实的,而 B和;&安培; ç
如果 A
是假的。
So in your case, it returns b || c
if a
is true, and b && c
if a
is false.
这篇关于什么&QUOT;&QUOT;和&QUOT;:&QUOT;在布尔语句呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!