본문 바로가기

프로그래머스

[프로그래머스] 두 정수 사이의 합_ JAVA

● 풀이

 

class Solution {
    public long solution(int a, int b) {
        long answer = 0;
        if(a<b){
            
            for(int i =a; i<=b; i++){
                answer += i;
            }
        }else if(a > b){
            for(int i = a; i>=b; i--){
                answer += i;
            }
        }else
            answer = a;
        
        return answer;
    }
}