inblog logo
|
stupefyee
    알고리즘문제풀기

    [JAVA 문제 풀이] 짝수의 합

    Stupefyee's avatar
    Stupefyee
    Nov 19, 2024
    [JAVA 문제 풀이] 짝수의 합
    Contents
    내가 작성한 코드다른 사람의 코드
    notion image
     

    내가 작성한 코드

    💡
    class Solution { public int solution(int n) { int answer = 0; for(int i = 1; i <= n; i++) { if(i % 2 == 0) { answer += i; } } return answer; } }
     

    다른 사람의 코드

    💡
    class Solution { public int solution(int n) { int answer = 0; for(int i=2; i<=n; i+=2){ answer+=i; } return answer; } }
    Share article
    Contents
    내가 작성한 코드다른 사람의 코드

    stupefyee

    RSS·Powered by Inblog