我想在java中编写一些代码,可以在交换机中或多次调用同一个案例,使用一些代码,这些代码对于大多数或所有情况都是相同的。现在我必须为每个案例重复一半的代码,因为它被区分大小写的代码包围。在我的脑海中的代码会是这个样子,变化范围为0-3,并打破仅仅意味着停止执行,直到该情况下一个电话,我明白,这可能是除了碰坏如果存在的话,交换机多次调用同一个案例
switch(variable){
case 0:
case 1:
if(other factors)
//add item to next spot in array
case 2:
case 3://all cases
//add items to next 3 spots in array for all cases
break;
case 0:
case 1:
if(other factors)
//add item to next spot in array
case 2:
case 3://all cases
//add more items to next spot in array
break;
case 1:
case 2:
if(other factors2)
//add item to next spot in array
break;
case 3:
//add item to next spot in array
case 0:
case 1:
case 2://all cases
//add items to next spot in array
break;
case 1:
case 2:
if(other factors2)
//add item to next spot in array
break;
case 3:
//add item to next spot in array
}