[Java] 두 배열 인수의 곱셈
샘플코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public static void main(String[] args) {
int[] A = new int[]{5, 2, 6, 4};
int[] B = new int[]{-4, 0, 2, -4};
// -20 + 0 + 12 - 16 = -24
System.out.println("multiplication : "+multiplication(A, B));
}
public static int multiplication(int[] a, int[] b) {
int result = 0;
for (int x=0; x<a.length; x++) {
result = result + (a[x] * b[x]);
}
return result;
}
Leave a comment