java如何跳过循环中的特定数字
不知道怎么叫我的帖子
public NaturalNumberTuple(int[] numbers) {
int [] thisTuple = new int[numbers.length];
int count = 0;
for(int j = 0; j < numbers.length; j++){
if(numbers[j] > 0){
thisTuple[j] = numbers[j];
count++;
}
}
int[] newTuple = new int[count];
for(int i = 0; i < newTuple.length; i++){
int k = i;
while(thisTuple[k] <= 0){
k++;
}
newTuple[i] = thisTuple[k];
}
this.tuple = newTuple;
}
这是我创建新NaturalNumber元组的代码片段
这就是我想要使用的数组:int[]tT2={1,2,4,-4,5,4,4}; 我只想使用大于0的自然数,我的问题不是去掉负数,而是我的控制台给了我这个:Tuple(数字:1,2,4,5,5,4)。 问题是,如果我跳过while循环中的负值来获得更高的(k),我必须在for循环中传递相同的(k),我不想传递,因为我已经在数组中得到了它。我希望你能理解我的问题。 抱歉英语不好
编辑:不能像系统一样使用java本身的任何方法。阵列拷贝
共 (0) 个答案