Java
프로그래머스: 음양 더하기
Daeryuk Kim
2024. 1. 20. 17:07
class Solution {
public int solution(int[] absolutes, boolean[] signs) {
int answer = 0;
for (int x=0; x<signs.length; x++) {
if (signs[x] == false) {
absolutes[x] = absolutes[x] * -1;
}
answer += absolutes[x];
}
return answer;
}
public static void main(String[] args) {
int[] absolutes = {4,7,12};
boolean[] signs = {true,false,true};
Solution sol = new Solution();
int result = sol.solution(absolutes, signs);
System.out.println(result);
}
}