Multiple conditions in ternary conditional operator?

后端 未结 7 858
醉酒成梦
醉酒成梦 2021-01-04 12:20

I am taking my first semester of Java programming, and we\'ve just covered the conditional operator (? :) conditions. I have two questions which seem to be wanting me to \"n

7条回答
  •  生来不讨喜
    2021-01-04 13:00

    Parentheses are like violence: if it's not working, use more.

    But seriously:

    ( condition A ? value A :
      ( condition B ? value B : 
        ( condition C ? value C :
           ...
        )
      )
    )
    

    And please, don't ever write code like that for anything important.

提交回复
热议问题