62,620
社区成员
发帖
与我相关
我的任务
分享
import java.util.ArrayList;
public class TwoArrays {
public static Object[] thirdArray(int[] a, int[] b){
Object[] c = new Object[a.length];
ArrayList<Integer> listB = new ArrayList<Integer>();
ArrayList<Integer> listC = new ArrayList<Integer>();
for (int i : b){
listB.add(i);
}
for (int j=0;j<a.length;j++){
if(!listB.contains((Integer)a[j])){
listC.add(a[j]);
}
}
return listC.toArray();
}
public static void main(String[] args){
int[] first = {1,2,3,4,5,6};
int[] second = {2,5,6};
Object[] third = thirdArray(first, second);
for(Object i : third){
System.out.print(i + " ");
}
}
}
public class TwoArrays {
public static void main(String[] args) {
int[] a = { 1, 2, 3, 4, 5, 6 };
int[] b = { 2, 5, 6 };
int[] c = new int[a.length - b.length];
int l = 0;
int k = 0;
for (int i = 0; i < a.length; i++) {
for (int j = k; j < b.length; j++) {
if (a[i] == b[j]) {
k++;
break;
} else if (a[i] < b[j]) {
c[l] = a[i];
l++;
break;
}
}
}
printArray(c);
}
public static void printArray(int[] arr){
System.out.print("[");
for(int a = 0;a<arr.length;a++){
if(a!=arr.length-1)
System.out.print(arr[a]+",");
else
System.out.println(arr[a]+"]");
}
}
}
int[] a = { 1, 2, 3, 4, 5, 6 };
int[] b = { 2, 5, 6 };
int[] c = new int[a.length - b.length];
int l = 0;
int k = 0;
for (int i = 0; i < a.length; i++) {
for (int j = k; j < b.length; j++) {
if (a[i] == b[j]) {
k++;
break;
} else if (a[i] < b[j]) {
c[l] = a[i];
l++;
break;
}
}
}
for (int s : c) {
System.out.print(s);
}
