[프로그래머스] flag에 따라 다른 값 반환하기

Seah Lee·2023년 6월 19일
0

프로그래머스

목록 보기
13/57

class Solution {
    public int solution(int a, int b, boolean flag) {
        
        int result = 0;
        
        if (flag==true) result = a+b;
        else result = a-b;
        
        return result;
    }
}

[다른 사람의 풀이]

class Solution {
    public int solution(int a, int b, boolean flag) {
        return flag ? a + b : a - b;
    }
}

내가 제일 못 쓰는 ? : 구문.. 잘 쓰면 저렇게 코드가 짧아 지는데....

profile
성장하는 개발자

0개의 댓글