Java, questions about switches and cases?

前端 未结 5 460
轻奢々
轻奢々 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:26

    All you can do is do not apply break in between like

    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    do action 1;
    break
    case 6:
    case 7:
    do action 2;
    break
    default : break;
    

    or use if-else if you have range of value ..

提交回复
热议问题