Recent Posts
Recent Comments
밍쎄의 코딩공간
프로그래머스 LV.0 - 홀짝에 따라 다른 값 반환하기 본문
class Solution {
public int solution(int n) {
int answer = 0;
if(n % 2 == 1){
for(int i = 1; i <= n; i += 2) answer += i;
}
else{
for(int i = 2; i <= n; i += 2) answer += (i*i);
}
return answer;
}
}
https://school.programmers.co.kr/learn/courses/30/lessons/181935?language=java
728x90
'프로그래머스 > 프로그래머스 LV.0' 카테고리의 다른 글
프로그래머스 LV.0 - 이어 붙인 수 (0) | 2023.07.31 |
---|---|
프로그래머스 LV.0 - flag에 따라 다른 값 반환하기 (0) | 2023.07.30 |
프로그래머스 LV.0 - 문자열 겹쳐쓰기 (0) | 2023.07.28 |
프로그래머스 LV.0 - 공배수 (0) | 2023.07.27 |
프로그래머스 LV.0 - 홀짝 구분하기 (0) | 2023.07.26 |