private String appStatus[]={"system", "start", "stop" , "install", "uninstall"};
private int appStatusWeight[]={1000,20,20,100,100};
第二個方案生成新的權重值陣列的方法
public static List<Integer> eachIntArrayValueSum(List<Integer> intArray) {
Integer currentMaxWeight = 0;
List<Integer> newWeightList = new ArrayList<>();
for (int i = 0; i < intArray.size(); i++) {
int currentWeight = 0;
if (i == 0) {
currentMaxWeight = intArray.get(i);
currentWeight = intArray.get(i);
newWeightList.add(currentWeight);
continue;
}
currentWeight = currentMaxWeight + intArray.get(i);
currentMaxWeight = currentWeight;
newWeightList.add(currentWeight);
}
return newWeightList;
}
參考連結
Java 控制隨機數出現的概率
本作品採用《CC 協議》,轉載必須註明作者和本文連結