我需要创建一个数组,看起来像这样:如何用简单的for循环创建一个数组?
[0,0,1,1,2,2,3,3,4,4....]
鉴于我下面的代码,我怎么能消除counter
?
int[] SomeArray = new int[24];
int counter = 0;
for(int x = 0 ; x < SomeArray.length-1 ; x++){
SomeArray[x] = counter;
SomeArray{x+1] = counter;
counter++;
}
当前代码仅通过一个步骤增加的x,所以输出应该是0 1 2 3 4 5 6 .... – beetlej