合并数组:
package pro;
//将两个int类型的数组合并成一个
public class MainClass {
public static int[] contact(int a[], int b[]) {
int[] f = new int[a.length + b.length];
for (int i = 0; i < f.length; i++)
if (i < a.length)
f[i] = a[i];
else
f[i] = b[i - a.length];
return f;
}
public static void main(String[] args) {
int a[] = { 1, 3, 4, 7 };
int b[] = { 2, 3, 5 };
int c[] = contact(a, b);
for (int i : c) {
System.out.print(i + " ");
}
Thread.currentThread().interrupt();
}
}
|
|