Java, questions about switches and cases?

前端 未结 5 461
轻奢々
轻奢々 2021-01-26 15:41

So I want to do a certain action 60 % of the time and another action 40% of the time. And sometimes have it doing neither. The best way I can think to do this is through switche

5条回答
  •  半阙折子戏
    2021-01-26 16:13

    If you want same action to happen for multiple cases, then don't put break. For example

    case 1:
    case 2:
    do action 1; break;
    

    In this case, action 1 will happen for both case 1 and 2.

提交回复
热议问题