코딩테스트/프로그래머스

프로그래머스 - 음양 더하기 (상준)

sunNprize 2022. 1. 4. 17:07
package test;

/*

 */

public class 음양_더하기 {
    public static void main(String[] args) {

        int[] absolutes = {4, 7, 12};
        boolean[] signs = {true, false, true};

        Solution6 Solution6 = new Solution6();
        Solution6.solution(absolutes, signs);

    }
}

class Solution6 {


    public int solution(int[] absolutes, boolean[] signs) {
        int answer = 0;
        for (int i = 0; i < signs.length; i++) {
            if (signs[i]) {
                answer += absolutes[i];
            } else {
                answer -= absolutes[i];
            }
        }
        System.out.println("answer = " + answer);

        return answer;
    }
}