백준, 프로그래머스

15-내적

숲별 2022. 9. 28. 23:17
728x90

길이가 같은 두 1차원 정수 배열 a, b가 매개변수로 주어집니다. a와 b의 내적을 return 하도록 solution 함수를 완성해주세요.이때, a와 b의 내적은 a[0]*b[0] + a[1]*b[1] + ... + a[n-1]*b[n-1] 입니다. (n은 a, b의 길이)

 

 

class Solution {
    public int solution(int[] a, int[] b) {
        int answer = 0;
        for(int i=0;i<a.length;i++){
            answer +=a[i]*b[i];
        }
        return answer;
    }
}

 

 

 

 

 

https://school.programmers.co.kr/learn/courses/30/lessons/70128