获得5个数字的序列我想从一个数组中获得5个数字的序列。 例如:如何从一个数组
int arr1[] = {3,88,99,5,4,6,22,32,7,45}; // array where there is the sequence 3,4,5,6,7
Vector<Integer> myVec = new Vector<Integer>(); // vector wehre to save the sequence
现在我有什么做的就是从数组的顺序? 我在这里有一个代码,但它不能正常工作:
for(int i = 0; i < arr1.length -1; i++) {
int a = arr1[i];
int b = arr1[i+1];
int c = b - a;
if(c == 1) {
myvec.add(arr1[i]);
}
}
我应该如何改变我的代码来解决这个问题?
使用Arrays.sort(),然后套用您的逻辑 – TheLostMind
不知道它是什么,你要acheive – Ar3s
我想把序列“3,4,5,6, 7“从arr1在myvec。 – CMS