Multiple conditions in ternary conditional operator?

后端 未结 7 900
醉酒成梦
醉酒成梦 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:07

    (month==1)?"jan":(month==2)?"feb": (month==3)?"mar": (month==4)?"apr": (month==5)?"may":(month==6)?"jun": (month==7)?"jul":(month==8)?"aug": (month==9)?"sep": (month==10)?"oct": (month==11)?"nov": (month==12)?"dec":null

    you got it right, the only thing you need is the null at the end when you finish thats all.

提交回复
热议问题