class Fcfs
{
public static void main(String[] args)
{
int [] a = new a[]{1,2,3,4};
int [] b = new b[]{9,8,7};
//以下我是想将数据a与b合并,不知可以实现吗???
}
}
结果是这样的:得到数组c,它的数值是数组a与b的合并的结果!!!!!
c的结果是:{1,2,3,4,9,8,7}
希望可以得到兄弟们的帮助!!!!
谢谢了!!!!
------解决方案--------------------
int c = new int[a.length + b.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);
------解决方案--------------------
int [] a = new a[]{1,2,3,4};
-----------------------------
LZ的数组定义都出错了,,new int{}{1,2,,3,4};
int[] a = new int[] { 1, 2, 3, 4 };
int[] b = new int[] { 9, 8, 7 };
int result[] = new int[a.length + b.length];
for (int i = 0; i < a.length; i++) {
result[i] = a[i];
}
int aLength=a.length;
for (int i = 0; i < b.length; i++) {
result[aLength+i] = b[i];
}
for (int i = 0; i < result.length; i++) {
System.out.println(result[i]);
}