关于java中两个数组元素的计算,会得来!

有一道题:
数组A={1,2,3}
数组B={4,5,6}
现在题目的要求是:将数组A内的元素分别乘以数组B的元素,然后将乘积重新归为数组C,就像这样{4,5,6,8,10,12,12,15,18},请问这个方法怎么写?

public static void main(String[] args) {
// TODO Auto-generated method stub
int[] a = {1,2,3};
int[] b = {4,5,6};
int[] c = test(a,b);
}

public static int[] test(int[] a,int[] b){
int a_length = a.length;
int b_length = b.length;
int c_length = a_length * b_length;
int[] c = new int[c_length];
int num = 0;
for(int i=0;i<a_length;i++){
for(int j=0;j<b_length;j++){
int temp =  a[i] * b[j];
System.out.println(temp);
c[num++] = temp;
}
}
return c;
}

追问

oh my god!原来是这样,听君一言,真是茅塞顿开,太感谢了!!

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答