我正在嘗試使用自定義值填充給定另一個數組的數組。舉例來說,如果我的基地是[2,3,1]
數組應該是這樣的:當我到達[2,3,1]
在Java中使用ArrayList開發自定義計數
0,0,0
0,0,1
0,1,0
0,1,1
0,2,0
0,2,1
0,3,0
0,3,1
1,0,0 and so on...
循環應該結束。我對代碼進行了一些更改,因此可能會比以前更糟。
max=0;
while (!(power.containsAll(listPot))){
while ((index<=listPot.get(pos))){ //Iterating the first digit
power.set(pos, index); //Updating the value
index++; //Increasing up to the limit found on listPot
}
index=0; //Reset the counter to put into the Array
if(max<limit){ //max would be the position of the next digit
max++;
}
if(power.get(max)<listPot.get(pos)){ //If next digit is < limit
index++; //move the index forward
power.set(max, index); //Increase the next digit
while (pos>=0){ //Removing the previous digits, like from 199 to 200
power.set(pos, 0);
pos--;
}
index=0;
}
else { //I increase max position again and proceed like above
pos=max;
max++;
while (pos>=0){ //Removing previous digits
power.set(pos, 0);
pos--;
}
index++; //Increasing the value to input
power.set(max, index);
}
index=0; //Reset the counters
pos=0;
}
主循環在數組不同時迭代。我初始化了全長爲零的新長度。另一個是目標之一。
編輯:我想在數組的每個位置迭代自定義限制的值。我將在每個循環中使用數組來加載一個給定數字的除數的分離數組。我向該方法提供了一個具有主要因素的數組,另一個使用了每個因子的權力。
對於900,結果是素數因子爲[2,3,5],功率爲[2,2,2]。這個特殊情況應該是基3迭代,因爲所有元素都是2.這對所有情況都是不可能的,所以我試圖做更靈活的事情。
當我移動到數組的下一個位置時,我的問題就出現了,所以我正在尋求幫助,以便使用變量正確循環來自數字的值。
你能告訴我們你想達到什麼目的嗎?你的問題很難理解 –
那麼,你的問題是什麼? –
我不明白:你想要構建的數組是什麼? –