我困在一個問題上。我應該添加兩個不同的arrayd的對應單元格,然後用總和填充第三個數組到相應的單元格,例如我有ar1 = {4,6,3}和ar2 = {8,5,6},而我必須填寫第三個數組,其總數爲空,如ar3 = {12,11,9}。這是我到目前爲止的代碼:添加兩個陣列的相應單元
class sumOfArrays
{
public static void main (String[] args)
{
int[] arrA = { 11, -27, 89, 17};
int[] arrB = {-3, 24, -9, -16};
int[] sum = { 0, 0, 0, 0};
for(int i = 0; i < arrA.length - 1; i++)
{
for(int j = 0; i < arrB.length - 1; i++)
{
sum[arrA[i] + arrB[j]];
}
}
System.out.println("sum: " + sum[0]+"," + sum[1] + "," + sum[2] + "," + sum[3]);
}}
我堅持,並希望一些指導。謝謝大家先進!