We can try it.
int START = 3;
int score = 0;
boolean[] rounds = { true, false };
for (int i = 0; i < rounds.length; i++) {
score += (rounds[i]) ? i + START : 0;
System.out.format("i is %d, score is %d%n", i, score);
}
Output:
i is 0, score is 3
i is 1, score is 3
So the first time through the loop i
is 0 and rounds[i]
is true
. In this case Java adds i
and START
to get 3 and adds this to score
. Second time i
is 1
and rounds[i]
is false
, so instead just 0 is added.
The statement you ask about adds a value to score
. The value added is i + START
if rounds[i]
can be evaluated to true and 0 if it’s false
. If i
and START
are both numeric, a number will be added. If score
is numeric, adding 0 usually makes no difference, so you may think of the statement as adding a value only if rounds[i]
is true.
so it is score += round[i] == i+start or == 0.
No, there is no implicit ==
comparison in the statement (as others have said, it requires that rounds[i]
is a Boolean value, true or false).