๐ก ์ง์ ํผ ์ฝ๋
์ด๋ฒ์๋ ๋๊ฐ์ง ๋ฐฉ๋ฒ์ผ๋ก ํ์ด๋ดค๋ค.
์ผํญ ์ฐ์ฐ์ ์ฌ์ฉ vs IF ๋ฌธ ์ฌ์ฉ
class Solution {
public int solution(int a, int b, boolean flag) {
int answer = 0;
answer = flag ? a+b : a-b;
return answer;
}
}
์๋ฌด๋๋ ์ผํญ์ฐ์ฐ์๊ฐ ๋ ์ข์๋ณด์ธ๋ค!
class Solution {
public int solution(int a, int b, boolean flag) {
int answer = 0;
if ( flag == true){
answer = a + b;
} else {
answer = a - b;
}
return answer;
}
}