what does "this.x = x < 0? 0 : x; this.y = y < 0? 0 : y;" mean?

Vivi Xu

I have no idea what does this mean:

this.x = x < 0 ? 0 : x;
this.y = y < 0 ? 0 : y;

I could not find the meaning of these operators, any help will be greatly appreciated!

Suresh Atta

Yes. That Terinary (or Conditional) Operator in java. A short hand for if and else condition.

The code this.x = x < 0? 0 : x; equivalent to

if (x<0) {
    this.x = 0
} else{
    this.x =x
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事